Repository navigation
feat(Popover)!: let Popover.Trigger use its child as the trigger - #1309
Conversation
🦋 Changeset detectedLatest commit: e7cebcc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
🟡 Changes recommended
The slotted disabled trigger omits required aria-disabled, and the changeset lacks a breaking-change notice and migration guidance for affected asChild callers.
2 open issues
What changed in this PR
This PR makes Popover.Trigger honor asChild, allowing a focusable child to receive popover semantics, keyboard interaction, and focus restoration in the Click UI component library.
Changes:
- Slots the child when
asChildis enabled while preserving legacy rendering otherwise. - Handles native button types separately from
ButtonandIconButtonvariants. - Adds regression tests, a usage story, and a minor changeset.
Tests and browser accessibility checks were not run during this review.
| File | Description |
|---|---|
src/components/Popover/Popover.tsx |
Implements child-based triggers and button-type handling. |
src/components/Popover/Popover.test.tsx |
Covers semantics, keyboard behavior, form safety, and compatibility. |
src/components/Popover/Popover.stories.tsx |
Demonstrates a Button used directly as the trigger. |
.changeset/feat-popover-trigger-as-child.md |
Documents the feature and changed wrapper behavior. |
Review effort: Balanced
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 4173ce7. Configure here.
|
Hi click-ui team, |
Chromatic Storybook
Built from commit: Statuses as of the end of the run. The build link shows the live review state. |



Description
Why
Popover.Triggercan't be used properly from the keyboard today. It always wraps its children in adiv, and Radix makes thatdivthe trigger. So thedivgetsaria-haspopup,aria-expandedandtype="button", but it can't take focus and it isn't a button.What that means for people using a keyboard or a screen reader:
Linkchild, Tab never reaches the trigger, so the popover can't be opened without a mouse.Buttonchild, Enter opens the popover, but the button never says whether it is open or closed. After Escape, focus drops to<body>instead of going back to the button.asChildis already in the trigger's types, but passing it does nothing.DateDetailsis built onPopover.Trigger, so its details are mouse only for the same reason.Before and after
The new
Trigger As Childstory on main (left) and with this change (right), with the same keys on both sides: Tab, Enter, Escape. The lines under each side show where focus is and what a screen reader gets.What this PR changes
Popover.Triggernow supportsasChild. The single child becomes the popover button, soaria-haspopup,aria-expanded, opening from the keyboard and the focus return land on a focusable element instead of the wrapperdiv.asChild, a native<button>child getstype="button". AButtonorIconButtonchild keeps its variant and getshtmlType="button", so it doesn't submit a form.asChildthe output is unchanged.<button>child getsaria-disabled="true"next todisabled, as AGENTS.md section 7 asks. It is only added when the trigger is disabled, so aButtonchild keeps thearia-disabledit sets for its owndisabledorloading.Links and tickets
aria-expandedproblem for Popover.Tooltip.Trigger, and fix(Dropdown)!: make the trigger's child the menu button #1259 does it forDropdown.Trigger.Good to know
asChild: it did nothing until now, so your child was still wrapped in adiv. With this change the wrapper is gone and your child is the trigger, so it must be focusable and forward its props andref. The changeset marks this as Breaking: with a migration note, like fix(Tooltip)!: forward the ref and props of Tooltip.Trigger with asChild #1258 did for Tooltip.asChild={false}keeps today's output (Radix's own button around the wrapper). A test pins it. Happy to drop that if you'd rather treatfalselike the default.type: I followed the rules from the fix(Dropdown)!: make the trigger's child the menu button #1259 review:type="button"for a native button,htmlType="button"forButtonandIconButton, and for other components only atypepassed to the trigger. They're inline so this PR doesn't depend on the draft. OncenativeButtonTypePropslands this becomes one call.refforwarding, on purpose. Forwarding therefturns on the truncation tooltip ofEllipsisContent component={Popover.Trigger}, the break that came up in fix(Tooltip)!: forward the ref and props of Tooltip.Trigger with asChild #1258. I can add it with a migration note if you want it here.Trigger As Childstory for the docs. Noplayor focus-visible story, following the review on fix(SplitButton): make the menu half a keyboard-accessible menu button #1278. The keyboard checks are unit tests.Tests
Eleven new unit tests in
Popover.test.tsx. Each one fails on main, or pins today's behaviour.asChild, the child gets the ARIA attributes, opens from the keyboard and gets focus back on Escape.ButtonorIconButtonchild keeps its variant and doesn't submit a form.aria-disabled, and a disabled or loadingButtonchild keeps its own.asChild, or withasChild={false}, the output is the same as today.yarn test:visual Popoverpasses (34 of 34), no snapshots regenerated.Not tested
Checklist
Contribution
buildandbuild-storybookwork locallyAccessibility
aria-labelChecked in the built Storybook in Chrome: 2.1.1 Keyboard, 2.4.3 Focus Order, 2.4.7 Focus Visible, 2.5.8 Target Size (the button is 128×32), 4.1.2 Name, Role, Value. Not checked: screen reader announcements.
Screenshots
The before and after is under Description. This is the moment after Escape: on main focus is lost, with this change it is back on the button.
Note
Medium Risk
Breaking API change for existing
asChildusage, plus nuanced prop merging on triggers inside forms and disabled/loading buttons.Overview
Popover.Triggernow honorsasChild: with it set, the single child is merged into Radix’s trigger (no wrapperdiv), so ARIA popover state, keyboard open/close, and focus return land on a focusable element.Behavior without
asChildis unchanged (still a styled wrapperdiv).asChild={false}keeps Radix’s button around that wrapper.Implementation details in
Popover.tsx: conditionalasChildonRadixPopover.Trigger, mapstypevshtmlTypeforButton/IconButtonso form submit isn’t triggered, and appliesaria-disabledonly when the trigger is disabled soButtonloading/disabled handling isn’t overwritten.Breaking for consumers that already passed
asChild(it was previously a no-op): the child must be focusable and forward props/ref. A changeset documents migration.Adds a TriggerAsChild Storybook story and a large
Triggertest suite (keyboard, props merge, disabled states, default vsasChild={false}).Reviewed by Cursor Bugbot for commit e7cebcc. Bugbot is set up for automated code reviews on this repo. Configure here.