Skip to content
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

Is there a way to prevent closing the dropdown when a MenuItem which has a sub menu is clicked? #29

Open
arikimolloy opened this issue Sep 19, 2019 · 0 comments

Comments

@arikimolloy
Copy link

arikimolloy commented Sep 19, 2019

I have a multi-level dropdown via nested MenuItems, and if I have a MenuItem which has sub-MenuItems and I click on it, I would rather it didn't close the entire dropdown. This is important for touch interaction (mobile devices) so that the user can open the sub-menu (because there is no mouse hover on mobile.

In my case only the sub-MenuItems are items where I perform an action on their selection, the parent MenuItem is just used as an entry-point to the sub menu. E.g. a parent MenuItem could be "Find" and the sub-MenuItems could be "Find next" "Find previous" "Find in selection". If I click "Select x..." I don't want the whole dropdown to close, only when I click the sub-MenuItems.

Currently my workaround is very ugly:
`const [mainDropdownIsOpen, setMainDropdownIsOpen] = useState(false);

return (
<Dropdown
onToggle={setMainDropdownIsOpen}
open={mainDropdownIsOpen}
disabled={disabled}
onClick={e => {
// workaround to prevent menu from closing on clicking of a
// parent MenuItem with sub-MenuItems (e.g. "Select view")
if (e.target.parentElement.className.includes('dropdown-submenu')) {
setMainDropdownIsOpen(true); // re-open the dropdown
}
}}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants