-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Menu: throw when subcomponents are not rendered inside top level Menu #67411
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
bb3bf84
to
df87182
Compare
Flaky tests detected in 5fb1df2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12081605771
|
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.
LGTM 👍 thank you 🚀
throw new Error( | ||
'Menu.CheckboxItem can only be rendered inside a Menu component' | ||
); |
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 for context to anyone else reading this: throwing an error in this scenario makes sense even if we just look at Ariakit - it is consistent with how Ariakit does it:
As you can see, if we don't have this check, Ariakit will throw this error:
MenuItem must be wrapped in a MenuList, Menu or Menubar component
however, relying on this would be confusing, since our Menu
components don't necessarily follow the same naming scheme.
packages/components/CHANGELOG.md
Outdated
|
||
### Internal | ||
|
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.
No need to add yet another "Internal" section.
### Internal |
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.
My bad, I was meant to rename it to "Experimental" and I forgot to do it. Will amend and merge
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.
Makes sense 👍
…WordPress#67411) * Menu: throw when subcomponents are not rendered inside top level Menu * CHANGELOG * Remove unnecessary optional chaining * Rename changelog section --- Co-authored-by: ciampo <[email protected]> Co-authored-by: tyxla <[email protected]>
…#67411) * Menu: throw when subcomponents are not rendered inside top level Menu * CHANGELOG * Remove unnecessary optional chaining * Rename changelog section --- Co-authored-by: ciampo <[email protected]> Co-authored-by: tyxla <[email protected]>
What?
Part of #66530
Extracted from #66383
Add a check for all
Menu
subcomponents, so that they throw if not rendered inside a parentMenu
component.Why?
This check ensures that the
Menu
compound component is used as intended (see #66530)How?
We perform a check on the internal component's context (which is created and exposed in the top level
Menu
component)Testing Instructions
Try to render any subcomponents in isolation (ie. not inside a
Menu
component) — the component should throw an error.