Skip to content

refactor(ui): Improve UserButton accessibility#8325

Draft
alexcarpenter wants to merge 13 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Draft

refactor(ui): Improve UserButton accessibility#8325
alexcarpenter wants to merge 13 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter
Copy link
Copy Markdown
Member

@alexcarpenter alexcarpenter commented Apr 15, 2026

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton popover. The popover contains mixed content (profile preview, action buttons, session cards, footer) — not a flat action list — so menu semantics were misleading screen readers.

What changed

  • Dialog semantics — popover is now role="dialog" with labeled role="group" sections ("Account actions", "Active sessions")
  • Focus management — uses floating-ui's useInteractions (useClick, useRole, useDismiss) instead of manual onClick/aria-* wiring. Focus moves to the dialog container on open, Tab is trapped inside, Escape restores focus to the trigger
  • Identity-first trigger label — "First Last - Open account panel" instead of "Open user menu"
  • Removed hard-coded role="menuitem" from Action/ExtraSmallAction components — no caller uses menu semantics

Fixes USER-4842

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment May 19, 2026 1:13am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: ae1e533

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

This PR includes changesets to release 20 packages
Name Type
@clerk/ui Patch
@clerk/shared Patch
@clerk/localizations Patch
@clerk/astro Patch
@clerk/chrome-extension Patch
@clerk/react Patch
@clerk/vue Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing 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

@alexcarpenter alexcarpenter marked this pull request as ready for review April 23, 2026 17:14
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request updates the UserButton component's accessibility architecture by replacing the menu-based pattern (with role="menu" and role="menuitem") with a dialog-based pattern (role="dialog" with grouped actions). The changes include localized labels for the popover and action groups, identity-first trigger text that displays the user's name, and enhanced focus management leveraging Floating UI's interaction system. The Popover element gains modal behavior support, and the usePopover hook is extended with role interactions and prop getter functions. Comprehensive tests verify the new dialog semantics and focus trapping behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(ui): Improve UserButton accessibility' clearly and concisely summarizes the main change: enhancing accessibility for the UserButton component through refactoring.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the changes: replacing menu/menuitem ARIA roles with dialog/group roles, improving focus management with floating-ui interactions, and updating trigger labels for identity-first accessibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/ui/src/components/UserButton/__tests__/UserButton.test.tsx`:
- Around line 243-266: The current test "traps focus within the popover when
open" only asserts the trigger loses focus on Tab, which can pass even if focus
moves outside the dialog; update the loop to assert that the dialog element
(retrieved as dialog = screen.getByRole('dialog', { name: 'Account panel' }))
contains the active element after each await userEvent.tab() call instead of
checking expect(trigger).not.toHaveFocus(); i.e., replace the per-iteration
assertion with a containment check like dialog.contains(document.activeElement)
(using the existing dialog variable and userEvent.tab()) so each Tab verifies
focus remains inside the popover.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6d4f3cc8-0b08-4506-8719-c6ce29033b7f

📥 Commits

Reviewing files that changed from the base of the PR and between e73d266 and 73355ba.

📒 Files selected for processing (10)
  • .changeset/user-button-a11y.md
  • packages/localizations/src/en-US.ts
  • packages/shared/src/types/localization.ts
  • packages/ui/src/components/UserButton/SessionActions.tsx
  • packages/ui/src/components/UserButton/UserButtonPopover.tsx
  • packages/ui/src/components/UserButton/UserButtonTrigger.tsx
  • packages/ui/src/components/UserButton/__tests__/UserButton.test.tsx
  • packages/ui/src/components/UserButton/index.tsx
  • packages/ui/src/elements/Popover.tsx
  • packages/ui/src/hooks/usePopover.ts

Comment thread packages/ui/src/components/UserButton/__tests__/UserButton.test.tsx
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8325

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8325

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8325

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8325

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8325

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8325

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8325

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8325

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8325

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8325

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8325

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8325

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8325

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8325

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8325

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8325

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8325

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8325

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8325

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8325

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8325

commit: 86c0e3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant