Skip to content

Conversation

adamsamec
Copy link
Contributor

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.

@adamsamec adamsamec requested a review from a team as a code owner September 1, 2025 14:46
Copy link

github-actions bot commented Sep 1, 2025

📊 Bundle size report

✅ No changes found

Copy link

github-actions bot commented Sep 1, 2025

Pull request demo site: URL

@adamsamec adamsamec force-pushed the feat-detect-invalid-menu-grid-nesting branch from 5ac8512 to 42b818c Compare September 2, 2025 12:48
export const useCheckNesting = (ref: React.RefObject<HTMLElement>, componentName: NestingComponentName): void => {
'use no memo';

const { targetDocument } = useFluent();
Copy link
Contributor

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') {
Copy link
Member

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?

Copy link
Contributor Author

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.

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.

4 participants