Skip to content

fix(navigation-menu): pass data-state to ViewportContentMounter#3923

Open
LongTangGithub wants to merge 1 commit into
radix-ui:mainfrom
LongTangGithub:fix/navigation-menu-content-data-state-viewport
Open

fix(navigation-menu): pass data-state to ViewportContentMounter#3923
LongTangGithub wants to merge 1 commit into
radix-ui:mainfrom
LongTangGithub:fix/navigation-menu-content-data-state-viewport

Conversation

@LongTangGithub

Copy link
Copy Markdown

Closes #3786

Description

NavigationMenuContent has two rendering paths depending on whether a
NavigationMenuViewport is present:

  • Without viewport — renders NavigationMenuContentImpl directly,
    with data-state passed explicitly. ✅
  • With viewport — hands off to ViewportContentMounter, which stores
    props in a shared Map that the viewport renders from. data-state was
    never included in this handoff. ❌

This meant that when using forceMount with a NavigationMenuViewport,
the rendered content elements had no data-state attribute at all, making it
impossible to target open/closed states in CSS or animations.

Fix

Extract openState from getOpenState(open) into a shared variable and
pass it as data-state to ViewportContentMounter, mirroring what was
already done for the non-viewport path.

Manual Testing

A new Storybook story ForceMountWithViewport has been added to reproduce
this scenario. To verify:

  1. Run pnpm dev and open Components/NavigationMenu → ForceMountWithViewport
  2. Hover over a trigger — the attribute should toggle between "open" and "closed" on the corresponding content element

Video Demo of Fix

data-attribute-fixmp4.mp4

@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8c88571

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@radix-ui/react-navigation-menu Major
radix-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

NavigationMenuContent when forceMount has no data-state attribute when used with NavigationMenuViewport

1 participant