-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for submenus #287
Comments
Right now I'm leaning towards the best design being to add an option type ParentProps = {
onKeyDown: (e: React.KeyboardEvent | React.MouseEvent) => void;
onClick: (e: React.KeyboardEvent | React.MouseEvent) => void;
tabIndex: -1;
ref: React.RefObject<T>;
role: 'menuitem';
'aria-haspopup': true;
'aria-expanded': boolean;
}; Very similar to div[role='menu'] {
visibility: hidden;
}
div[role='menu'].visible {
visibility: visible;
} // Inner menu
const Submenu = React.forwardRef((props: {
parentMenuItem: {
text: string;
children: { text: string }[];
},
...props,
}, ref) => {
const { parentProps, itemProps, isOpen } = useDropdownMenu(props.parentMenuItem.children.length, { submenu: true });
return (
<React.Fragment>
<a {...parentProps} ref={ref}>Parent menu item</a>
<div className={isOpen ? 'visible' : ''} role='menu'>
{props.parentMenuItem.children.map((child, i) =>
<a {...itemProps[i]}>{child.text}</a>
)}
</div>
</React.Fragment>
);
})
// Outer menu
const DropdownMenu = () => {
const items = [
{
text: 'I am a submenu',
children: [
{
text: 'I am a child of a submenu'
}
}
];
const { buttonProps, itemProps, isOpen } = useDropdownMenu(items.length);
return (
<React.Fragment>
<button {...buttonProps}>Example</button>
<div className={isOpen ? 'visible' : ''} role='menu'>
<Submenu {...itemProps[0]} parentMenuItem={items[0]} />
</div>
</React.Fragment>
);
} There's probably some issues with what I've drafted above but that would be the general idea, keep the hook mostly the same, implement the new |
Right now, the only fully supported implementation by our hook is a one level deep menu, submenus require extra keyboard controls and considerations that aren't currently implemented.
A merge request that closes this issue should ensure that the WAI-ARIA Practices are still followed to conformity for a vertical menu. This includes:
Right Arrow:
Left Arrow:
Escape:
The hook also supports the behavior of moving to the first menu item that starts with a specific printable character when it is pressed. If submenus are supported, that behavior should be contained to the current menu context (i.e. the menu within which elements currently have focus).
The text was updated successfully, but these errors were encountered: