-
Notifications
You must be signed in to change notification settings - Fork 42
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
Close nested MenuItem
s within Tile.MoreOptions
when clicked
#2452
base: main
Are you sure you want to change the base?
Conversation
@@ -111,6 +112,7 @@ export const MenuItem = React.forwardRef((props, forwardedRef) => { | |||
} | |||
|
|||
const parentMenu = React.useContext(MenuContext); | |||
const tileMoreOptionsContext = React.useContext(TileMoreOptionsContext); |
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.
Tile
depends on Menu
/MenuItem
but the vice-versa is not true, so it would be nice to decouple this component from Tile
.
We could create a context in Menu
/MenuItem
such that when it's set (to true
), the Menu
will automatically close. Then we can provide this context from Tile.MoreOptions
.
As a bonus, this approach would allow Tile.MoreOptions
to stay uncontrolled (i.e. it no longer needs to pass visible
to DropdownMenu
).
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.
Good idea! Implemented (2ac45b6).
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.
Just realized, this approach will only close the menu directly above it. It won't close the top-most menu which is want we want. Finding a solution.
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.
Fixed in d7d94d9
.
Changes
Fixes #2451.
Upon discussing internally, looks like handling the MenuItem closing on click instead of exposing the
close
function to the user was intentional.The existing
cloneElement
approach works only for top-level MenuItems withinTile.MoreOptions
. So, this PR uses a context approach to automatically close the menu upon clicking even the nestedMenuItem
s.This PR adds a context called
MenuCloseOnClickContext
. This wraps around aMenu
or a component that contains aMenu
. When set to true, any descendant MenuItem click will close the menu.Testing
Added e2e test.
Docs
Added changeset.