Repository navigation
feat(Popover)!: let Popover.Trigger use its child as the trigger - #1309
marcin-sieradzki wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: ea3f957 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
Chromatic Storybook
Built from commit: Statuses as of the end of the run. The build link shows the live review state. |
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.



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
Minor API break for existing asChild usage and trigger DOM structure changes; accessibility-sensitive trigger/type/disabled merging needs correct consumer upgrades.
Overview
Popover.Triggernow implementsasChild: the single focusable child receives trigger ARIA (aria-haspopup,aria-expanded, etc.), keyboard open/close, and focus return on dismiss, instead of an outer wrapperdivacting as the trigger.Breaking for callers already passing
asChild(previously a no-op): the wrapper is removed, so the child must be focusable and merge props/ref. Default behavior withoutasChildis unchanged;asChild={false}keeps the old Radix button + wrapper layout.Implementation maps
typecorrectly for native buttons vsButton/IconButton(htmlType), avoids accidental form submit, and only mergesaria-disabledfrom the trigger when disabled so design-system buttons keep their own disabled/loading semantics.Adds a changeset with migration notes, a
TriggerAsChildStorybook story, and broad unit tests (ARIA, keyboard, prop merge, disabled, form submit).Reviewed by Cursor Bugbot for commit ea3f957. Bugbot is set up for automated code reviews on this repo. Configure here.