davidtheclark / react-aria-menubutton

A fully accessible, easily themeable, React-powered menu button

Home Page:https://davidtheclark.github.io/react-aria-menubutton/demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using focusMenu

PleatherStarfish opened this issue · comments

After reading the documentation and looking at the demo code, I'm still confused about how to use focusMenu to move focus to the menu's first item when the menu is clicked. It's clear enough how to call focusMenu with an id and boolean to pragmatically open the menu, but this doesn't seem to work when I call it with onMenuToggle on the Wrapper itself.

For example, this doesn't work for me:

const NavbarButton = (props) => {
    const [openState, setOpenState] = useState({isOpen: false});
    const openClass = openState.isOpen ? 'open' : '';

    <Wrapper
        id={props.id}
        className={`${openClass}`}
        onMenuToggle={({isOpen}) => {
            openState.isOpen ? openMenu(props.id, { focusMenu: true }) : closeMenu(props.id, { focusMenu: true });
            setOpenState({isOpen})
            }
        }
    >

Am I doing that wrong, or is there another way to assign focus to the first item in the dropdown after clicking the Wrapper that I'm not understanding?

Do you have any working example hosted somewhere ?

Closing as inactive