Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); refactor(ui): Improve UserButton/OrgSwitcher accessibility by alexcarpenter · Pull Request #8325 · clerk/javascript · GitHub
Skip to content

refactor(ui): Improve UserButton/OrgSwitcher accessibility - #8325

Merged
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y
Jun 23, 2026
Merged

refactor(ui): Improve UserButton/OrgSwitcher accessibility#8325
alexcarpenter merged 25 commits into
mainfrom
carp/user-4842-improve-userbutton-a11y

Conversation

@alexcarpenter

@alexcarpenteralexcarpenter commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Replaces role="menu" / role="menuitem" with role="dialog" and role="group" in the UserButton and OrganizationProfile popovers. 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
  • 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

vercelBot commented Apr 15, 2026

Copy link
Copy Markdown

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

ProjectDeploymentActionsUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJun 23, 2026 12:36am
swingsetReadyReadyPreview, CommentJun 23, 2026 12:36am

Request Review

@changeset-bot

changeset-botBot commented Apr 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2dabbf1

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

This PR includes changesets to release 23 packages
NameType
@clerk/uiMinor
@clerk/sharedPatch
@clerk/localizationsPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/reactPatch
@clerk/swingsetPatch
@clerk/vuePatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/electronPatch
@clerk/expo-passkeysPatch
@clerk/expoPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/headlessPatch
@clerk/honoPatch
@clerk/mswPatch
@clerk/nextjsPatch
@clerk/nuxtPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/testingPatch

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

@coderabbitai

coderabbitaiBot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

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 nameStatusExplanation
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
Title check✅ PassedThe title accurately describes the main change: refactoring UserButton accessibility by changing from menu roles to dialog roles with improved focus management and localized labels.
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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

@pkg-pr-new

pkg-pr-newBot commented May 19, 2026

Copy link
Copy Markdown

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/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@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: 2dabbf1

The {{name}} - Open/Close account panel pattern and the LocalizationValue<'name'>
type narrowing will ship in a separate PR so the localization rollout can be
scoped and reviewed independently. This reverts the action key values and type
changes while keeping the three new optional label keys added in this PR.
Adds label__userButtonPopover, label__accountActions, and label__activeSessions
to all 48 non-English locale files so screen reader labels for the new dialog
structure are available in every supported language.
OrganizationSwitcher was missing dialog semantics and escape-to-close tests
that UserButton already had. Menu was missing a test verifying Tab exits the
menu (validating modal=false behaviour). These guard against regressions in
focus management across all Popover consumers.
The identity-first trigger label was reverted; E2E tests still expected
the old 'Open account panel' text.
@alexcarpenter
alexcarpenter merged commit a536a0d into mainJun 23, 2026
139 of 148 checks passed
@alexcarpenter
alexcarpenter deleted the carp/user-4842-improve-userbutton-a11y branch June 23, 2026 13:08
Sign up for freeto 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.

3 participants

@alexcarpenter@austincalvelage@maxyinger