-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Feat(react-menu-grid-preview): Detect invalid MenuGrid nesting #35128
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
base: master
Are you sure you want to change the base?
Feat(react-menu-grid-preview): Detect invalid MenuGrid nesting #35128
Conversation
📊 Bundle size report✅ No changes found |
Pull request demo site: URL |
...nts/react-menu-grid-preview/library/src/components/MenuGridRow/useCheckMenuGridRowNesting.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu-grid-preview/library/src/utils/useCheckNesting.ts
Outdated
Show resolved
Hide resolved
...s/react-menu-grid-preview/library/src/components/MenuGridItem/useCheckMenuGridItemNesting.ts
Outdated
Show resolved
Hide resolved
...omponents/react-menu-grid-preview/library/src/components/MenuGrid/useCheckMenuGridNesting.ts
Outdated
Show resolved
Hide resolved
5ac8512
to
42b818c
Compare
...omponents/react-menu-grid-preview/library/src/components/MenuGrid/useCheckMenuGridNesting.ts
Outdated
Show resolved
Hide resolved
export const useCheckNesting = (ref: React.RefObject<HTMLElement>, componentName: NestingComponentName): void => { | ||
'use no memo'; | ||
|
||
const { targetDocument } = useFluent(); |
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.
You can move this hook inside the dev environment conditional also
let current = ref.current?.parentElement; | ||
let role = current?.getAttribute('role'); | ||
while (current !== targetDocument?.body) { | ||
if (role === 'grid' || role === 'menuitem') { |
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.
why is the menuitem
role a breaking condition? Is it valid to put any of the MenuGrid components inside an element with role menuitem
?
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.
I thought that placing MenuGrid into role="menuitem" should be allowed for the case that the MenuGrid is inserted inline.
Description of changes
This PR adds a dev-only check for proper nesting of MenuGrid, MenuGridItem and MenuGridRow components, throwing an Error when invalid nesting is detected.