-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ensure all menu children are li elements
- wrap non-li children in li tags for consistency - assign tabIndex for visual focus to children with menuitem role - add active CSS class to focused MenuItem component - modify tests
- Loading branch information
Showing
6 changed files
with
135 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
export const isValidMenuItem = (node) => { | ||
const role = node.getAttribute('role') | ||
|
||
const menuItemCheck = | ||
role && ['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(role) | ||
const isMenuItem = (role) => { | ||
return ['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(role) | ||
} | ||
|
||
// UI Library MenuItem | ||
if (role === 'presentation') { | ||
return isValidMenuItem(node.children[0]) | ||
} else { | ||
return role !== 'separator' && menuItemCheck | ||
const isValidMenuItemNode = (node) => { | ||
if (node.nodeName === 'LI' && node.firstElementChild) { | ||
return isValidMenuItemNode(node.firstElementChild) | ||
} | ||
|
||
const role = node.getAttribute('role') | ||
return role && isMenuItem(role) | ||
} | ||
|
||
export const filterValidMenuItemsIndices = (children) => { | ||
const validIndices = [] | ||
children.forEach((node, index) => { | ||
if (isValidMenuItem(node)) { | ||
validIndices.push(index) | ||
export const getFocusableItemsIndices = (elements) => { | ||
const focusableIndices = [] | ||
elements.forEach((node, index) => { | ||
if (isValidMenuItemNode(node)) { | ||
focusableIndices.push(index) | ||
} | ||
}) | ||
return validIndices | ||
return focusableIndices | ||
} | ||
|
||
export const hasMenuItemRole = (component) => { | ||
return isMenuItem(component?.props?.['role']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters