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

Close nested MenuItems within Tile.MoreOptionswhen clicked #2452

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

r100-stack
Copy link
Member

@r100-stack r100-stack commented Feb 27, 2025

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 within Tile.MoreOptions. So, this PR uses a context approach to automatically close the menu upon clicking even the nested MenuItems.

This PR adds a context called MenuCloseOnClickContext. This wraps around a Menu or a component that contains a Menu. When set to true, any descendant MenuItem click will close the menu.

Testing

Added e2e test.

Docs

Added changeset.

@r100-stack r100-stack self-assigned this Feb 27, 2025
@r100-stack r100-stack marked this pull request as ready for review February 28, 2025 20:40
@r100-stack r100-stack requested a review from a team as a code owner February 28, 2025 20:40
@r100-stack r100-stack requested review from mayank99 and removed request for a team February 28, 2025 20:40
@@ -111,6 +112,7 @@ export const MenuItem = React.forwardRef((props, forwardedRef) => {
}

const parentMenu = React.useContext(MenuContext);
const tileMoreOptionsContext = React.useContext(TileMoreOptionsContext);
Copy link
Contributor

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Implemented (2ac45b6).

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d7d94d9.

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

Successfully merging this pull request may close these issues.

Clicking on submenu items in Tile's MoreOptions doesn't close the menu
2 participants