-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: focus-group
support toolbar
#19
Changes from 6 commits
f8ef60e
eac2178
45d0836
4189145
fdaff28
102b422
29f50f2
0227a49
7cbd649
57992fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const ROLES = { | ||
menuitem: ['menu', 'menubar'], | ||
option: ['listbox'], | ||
tab: ['tablist'] | ||
tab: ['tablist'], | ||
button: ['toolbar'], | ||
checkbox: ['toolbar'] | ||
} | ||
|
||
export function focusGroupKeyUX(options) { | ||
|
@@ -18,8 +20,10 @@ export function focusGroupKeyUX(options) { | |
} | ||
|
||
function findGroupNodeByEventTarget(eventTarget) { | ||
let itemRole = eventTarget.role | ||
let groupRoles = ROLES[itemRole] | ||
let itemRole = eventTarget.role || eventTarget.type || eventTarget.tagName | ||
if (!itemRole) return null; | ||
|
||
let groupRoles = ROLES[itemRole.toLowerCase()] | ||
if (!groupRoles) return null | ||
|
||
for (let role of groupRoles) { | ||
|
@@ -28,13 +32,25 @@ export function focusGroupKeyUX(options) { | |
} | ||
} | ||
|
||
function getItems(eventTarget, group) { | ||
if (group.role === "toolbar") return getToolbarItems(group) | ||
return group.querySelectorAll(`[role=${eventTarget.role}]`) | ||
} | ||
|
||
function getToolbarItems(group) { | ||
ai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let items = [...group.querySelectorAll('*')] | ||
return items.filter((item)=> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Format is not according to Prettier There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously I used only Editor Config for the project should I install Prettier auto formatter ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Editor Config is for general settings (indent, new line format, etc). Prettier is about formatting the code, where to add spaces, etc. I recommend installing it since it is an industry standard nowadays. But you can keep code formatting manually if you don’t want to install it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier is awesome I just clarified the info |
||
return item.role === 'button' || item.type === 'button' || item.role === 'checkbox' ||item.type === 'checkbox' | ||
}) | ||
} | ||
|
||
function isHorizontalOrientation(group) { | ||
let ariaOrientation = group.getAttribute('aria-orientation') | ||
if (ariaOrientation === 'vertical') return false | ||
if (ariaOrientation === 'horizontal') return true | ||
|
||
let role = group.role | ||
return role === 'menubar' || role === 'tablist' | ||
return role === 'menubar' || role === 'tablist' || role === 'toolbar' | ||
} | ||
|
||
function keyDown(event) { | ||
|
@@ -45,7 +61,7 @@ export function focusGroupKeyUX(options) { | |
return | ||
} | ||
|
||
let items = group.querySelectorAll(`[role=${event.target.role}]`) | ||
let items = getItems(event.target, group); | ||
let index = Array.from(items).indexOf(event.target) | ||
|
||
let nextKey = 'ArrowDown' | ||
|
@@ -106,7 +122,7 @@ export function focusGroupKeyUX(options) { | |
inGroup = true | ||
window.addEventListener('keydown', keyDown) | ||
} | ||
let items = group.querySelectorAll(`[role=${event.target.role}]`) | ||
let items = getItems(event.target, group); | ||
for (let item of items) { | ||
if (item !== event.target) { | ||
item.setAttribute('tabindex', -1) | ||
|
@@ -126,7 +142,7 @@ export function focusGroupKeyUX(options) { | |
function click(event) { | ||
let group = findGroupNodeByEventTarget(event.target) | ||
if (group) { | ||
let items = group.querySelectorAll(`[role=${event.target.role}]`) | ||
let items = getItems(event.target, group); | ||
for (let item of items) { | ||
if (item !== event.target) { | ||
item.setAttribute('tabindex', -1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
package.json
→size-limit