Skip to content

feat(Popover)!: let Popover.Trigger use its child as the trigger - #1309

Open
marcin-sieradzki wants to merge 6 commits into
ClickHouse:mainfrom
marcin-sieradzki:feat/popover-trigger-as-child
Open

marcin-sieradzki wants to merge 6 commits into
ClickHouse:mainfrom
marcin-sieradzki:feat/popover-trigger-as-child

Conversation

@marcin-sieradzki

@marcin-sieradzki marcin-sieradzki commented Nov 15, 2026 •

Copy link
Copy Markdown

If this is already covered by the trigger work around #1259, I'm happy to close this PR.

Description

Why

Popover.Trigger can't be used properly from the keyboard today. It always wraps its children in a div, and Radix makes that div the trigger. So the div gets aria-haspopup, aria-expanded and type="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:

  • With a text or Link child, Tab never reaches the trigger, so the popover can't be opened without a mouse.
  • With a Button child, 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.
  • asChild is already in the trigger's types, but passing it does nothing.

DateDetails is built on Popover.Trigger, so its details are mouse only for the same reason.

Before and after

The new Trigger As Child story 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.

Before and after: Tab, Enter, Escape on main and with this change

What this PR changes

  • Popover.Trigger now supports asChild. The single child becomes the popover button, so aria-haspopup, aria-expanded, opening from the keyboard and the focus return land on a focusable element instead of the wrapper div.
  • With asChild, a native <button> child gets type="button". A Button or IconButton child keeps its variant and gets htmlType="button", so it doesn't submit a form.
  • Without asChild the output is unchanged.
  • A disabled native <button> child gets aria-disabled="true" next to disabled, as AGENTS.md section 7 asks. It is only added when the trigger is disabled, so a Button child keeps the aria-disabled it sets for its own disabled or loading.

Links and tickets

Good to know

  • Breaking, if you already pass asChild: it did nothing until now, so your child was still wrapped in a div. With this change the wrapper is gone and your child is the trigger, so it must be focusable and forward its props and ref. 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 treat false like the default.
  • Button 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" for Button and IconButton, and for other components only a type passed to the trigger. They're inline so this PR doesn't depend on the draft. Once nativeButtonTypeProps lands this becomes one call.
  • No ref forwarding, on purpose. Forwarding the ref turns on the truncation tooltip of EllipsisContent 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.
  • Stories: one Trigger As Child story for the docs. No play or 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.
  • Not changed: the default. Making the child the trigger by default would be breaking, so that's your call.

Tests

Eleven new unit tests in Popover.test.tsx. Each one fails on main, or pins today's behaviour.

  • With asChild, the child gets the ARIA attributes, opens from the keyboard and gets focus back on Escape.
  • A Button or IconButton child keeps its variant and doesn't submit a form.
  • A disabled native button child gets aria-disabled, and a disabled or loading Button child keeps its own.
  • Without asChild, or with asChild={false}, the output is the same as today.
  • yarn test:visual Popover passes (34 of 34), no snapshots regenerated.

Not tested

  • A screen reader.

Checklist

  • Breaking changes? (add migration notes in changesets)
  • Visual changes? (specify in changesets)
  • Design review needed?

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook)
  • build and build-storybook work locally
  • Tests and Stories are aligned with the changes

Accessibility

  • Keyboard - every action works with Tab / Enter / Space / Esc; focus is visible and returns to the trigger on close
  • Names — every control has a name that includes its visible label; icon-only controls take aria-label
  • Vision — colors come from tokens, focus ring shows, targets are at least 24×24 px

Checked 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.

After Escape: main on the left, this change on the right


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.Trigger now implements asChild: the single focusable child receives trigger ARIA (aria-haspopup, aria-expanded, etc.), keyboard open/close, and focus return on dismiss, instead of an outer wrapper div acting 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 without asChild is unchanged; asChild={false} keeps the old Radix button + wrapper layout.

Implementation maps type correctly for native buttons vs Button/IconButton (htmlType), avoids accidental form submit, and only merges aria-disabled from the trigger when disabled so design-system buttons keep their own disabled/loading semantics.

Adds a changeset with migration notes, a TriggerAsChild Storybook 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.

@changeset-bot

changeset-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ea3f957

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

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

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

@marcin-sieradzki
marcin-sieradzki marked this pull request as ready for review November 15, 2026 16:53
@XOP
XOP requested review from ariser and a balanced review from Copilot November 16, 2026 11:06
@XOP XOP added bug Something isn't working a11y Accessibility improvements good first issue Good for newcomers labels Nov 16, 2026

Copilot AI 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.

🟡 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 asChild is enabled while preserving legacy rendering otherwise.
  • Handles native button types separately from Button and IconButton variants.
  • 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

Comment thread src/components/Popover/Popover.tsx Resolved
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 671 stories published Open Storybook
UI Tests ⏳ 1 change must be accepted as baseline Open build

Built from commit: 1bf996ca8c3d8ab9e6715dfecb1ac8fcc650cf1a · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

@marcin-sieradzki marcin-sieradzki changed the title feat(Popover): let Popover.Trigger use its child as the trigger feat(Popover)!: let Popover.Trigger use its child as the trigger Nov 16, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4173ce7. Configure here.

Comment thread src/components/Popover/Popover.tsx Resolved

This branch has not been deployed

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

Labels

a11y Accessibility improvements bug Something isn't working good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants