Skip to content

fix (#3826): In DropdownMenu, allow Tab navigation to interactive elements w…#3833

Open
ahmadaurwahaj wants to merge 3 commits intoradix-ui:mainfrom
ahmadaurwahaj:fix/dropdown-menu-tab-navigation
Open

fix (#3826): In DropdownMenu, allow Tab navigation to interactive elements w…#3833
ahmadaurwahaj wants to merge 3 commits intoradix-ui:mainfrom
ahmadaurwahaj:fix/dropdown-menu-tab-navigation

Conversation

@ahmadaurwahaj
Copy link
Copy Markdown

Fixes #3826 - Dropdown Footer Accessibility Concern

Description

Currently, pressing Tab anywhere inside a DropdownMenu immediately closes it via event.preventDefault(). This means keyboard users cannot reach interactive elements placed inside the menu content that are outside of DropdownMenu.Item - such as footer buttons ("Apply", "Create New", "Save", etc.).

This is a real accessibility gap: it is a common pattern to put action buttons at the bottom of a dropdown panel, and those buttons are completely unreachable by keyboard.

Changes:

  • Replaced the blanket event.preventDefault() on Tab in MenuContentImpl's onKeyDown handler with smart Tab navigation logic.
  • Tab now cycles freely between tabbable elements within the menu content.
  • The menu closes (and focus returns to the trigger) only when Tab would move focus outside the content boundary:
    • Tab on the last tabbable element → menu closes
    • Shift+Tab on the first tabbable element → menu closes
  • Added a getTabbableCandidates() utility using TreeWalker to enumerate focusable elements within the content container.
  • Added a WithFooterActions Storybook story to demonstrate the fix.
  • Added unit tests covering boundary and mid-content Tab behaviour.

How to test manually:

  1. Run pnpm --filter storybook dev
  2. Open DropdownMenu → With Footer Actions
  3. Click "Open", then press Tab — focus should move through Cut → Copy → Paste → Delete → Apply → Create New
  4. Pressing Tab on "Create New" closes the menu
  5. Open again, Shift+Tab on the first item closes the menu

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 19, 2026

🦋 Changeset detected

Latest commit: 2d3d6e3

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

This PR includes changesets to release 5 packages
Name Type
@radix-ui/react-dropdown-menu Patch
@radix-ui/react-menu Patch
radix-ui Patch
@radix-ui/react-context-menu Patch
@radix-ui/react-menubar 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

@ahmadaurwahaj ahmadaurwahaj reopened this Mar 19, 2026
@ahmadaurwahaj ahmadaurwahaj marked this pull request as draft March 19, 2026 10:57
@ahmadaurwahaj ahmadaurwahaj marked this pull request as ready for review March 19, 2026 11:28
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.

Dropdown Footer Accessibility Concern

1 participant