Skip to content

feat(core): add XDSPopover component - #298

Merged
cixzhang merged 9 commits into
mainfrom
navi/feat/popover-only
Feb 27, 2026
Merged

cixzhang merged 9 commits into
mainfrom
navi/feat/popover-only

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Extracts XDSPopover from #286 so it can land independently. Typeahead and Tokenizer will follow in a separate PR.

What's included

  • XDSPopover component built on useXDSLayer
  • 12 placement options with anchored positioning
  • Click-outside and Escape to dismiss
  • Focus management (auto-focus first focusable element or heading)
  • Entry animation (fade + slide)
  • Default padding matching HoverCard
  • Accessible: role=dialog, aria-labelledby, focus trap
  • Tests and Storybook stories

What's NOT included (stays in #286)

  • XDSTypeahead — will be a follow-up PR
  • XDSTokenizer — will be a follow-up PR

Closes #175


Crafted with care by Navi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 23, 2026
@github-actions

github-actions Bot commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Layer · View in Storybook · 🆕 XDSPopover
Metric Before After Delta
Bundle Size (ESM) N/A 491B N/A
Lines of Code N/A 1550 -
Complexity N/A Very High (169) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 8.0KB 13.0KB 2.0KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Some feedback on the implementation. Also the contents in the popovers in storybook still appear blank. May have to do with some styling but if we can't figure it out I'll debug it manually on my laptop.

Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
@cixzhang

Copy link
Copy Markdown
Contributor Author

Addressed all 6 review comments:

  1. ✅ Removed hover trigger — XDSPopover is click-only, directs to XDSHoverCard
  2. ✅ Removed hasFocusTrap — always enforced, no escape hatch
  3. ✅ Inlined ClickPopover — no separate component
  4. ✅ Killed useEffects — removed initialIsShown, one useLayoutEffect remains for controlled state sync
  5. ✅ Added anchorRef — sibling-mode rendering, matches XDSTooltip pattern
  6. ✅ Clarified hook usage — ARIA/click applied imperatively via display:contents pattern (same as Tooltip)

Also added explicit color: colorVars['--color-text-primary'] to the container style in case the blank content issue is related to CSS variable inheritance in the top layer. The popover element stays in the DOM tree so variables should cascade, but this makes it explicit. If it's still blank after this push, it might be a Storybook CSS build issue worth debugging locally.

Net: -30 lines, simpler API (removed trigger, hasFocusTrap, initialIsShown; added anchorRef).

Comment thread packages/core/src/Layer/XDSPopover.tsx Resolved
@cixzhang

Copy link
Copy Markdown
Contributor Author

Clicking the popovers trigger while the popovers is visible appears to retrigger opening the popover layer.

@cixzhang

Copy link
Copy Markdown
Contributor Author

The contents still appear black but I'll manually debug this tomorrow.

@cixzhang

Copy link
Copy Markdown
Contributor Author

On mobile it seems like the latter has a hard time staying in the viewport. I think it could make sense for the popovers to be start aligned with the trigger rather than center aligned and we should flip alignment if there's not enough space in view port.

@cixzhang
cixzhang force-pushed the navi/feat/popover-only branch from ad95f43 to 445c750 Compare February 24, 2026 04:45
@cixzhang

Copy link
Copy Markdown
Contributor Author

Round 2 fixes pushed (rebased on main including React 19 upgrade):

  1. ✅ Elevation tokens — using elevationVars['--elevation-menu'] instead of raw box-shadow
  2. ✅ Toggle bug — added a guard against the light dismiss + click handler race condition. When the popover auto-dismisses (click outside), the trigger's click handler fires in the same event and would re-open it. Now tracks the last hide timestamp and skips re-opening within 50ms.
  3. ✅ Default alignment — changed from center to start. The layer's positionTryFallbacks: 'flip-block, flip-inline, flip-block flip-inline' already handles flipping when there's not enough viewport space.

Re: React 19 and the controlled state sync — the remaining useLayoutEffect syncs the external isShown prop to the hook's internal state. We could push this into useXDSPopover itself (add an isShown option) to eliminate the effect entirely. Want me to do that as part of this PR or as a follow-up?

@czarandy

Copy link
Copy Markdown
Collaborator

the popover examples look weird without any border or shadow

image

@cixzhang

Copy link
Copy Markdown
Contributor Author

Had to manually debug, but this is looking better now

@cixzhang

Copy link
Copy Markdown
Contributor Author

The keyboard interactions don't seem to work in the examples. Likely this is due to the popover setting click interactions manually on child elements. It might be better to be more explicit about showing/hiding the popover via onClick interactions and then the children would just be about setting the anchor ref.

@thedjpetersen

Copy link
Copy Markdown
Contributor

🤖 Night Watch QA Report

visual-regression failing

The visual regression check is failing due to screenshot baseline drift. Several recent merges to main (XDSStack consolidation, TopNav mega menu changes, Button endSlot) updated component rendering, so branches that haven't rebased will show pixel diffs.

Fix: Rebase on main and update snapshots:

git rebase main
yarn playwright test e2e/visual-regression.spec.ts --update-snapshots
git add -A && git commit -m "chore: update visual regression snapshots"

All other CI checks are passing. ✅


Night Watch QA — automated CI health check

@cixzhang
cixzhang force-pushed the navi/feat/popover-only branch 2 times, most recently from 9333208 to 0cf366f Compare February 27, 2026 20:12
@github-actions

github-actions Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

❌ Visual Regression — Failed

Screenshots differ from baselines for: XDSHoverCard, XDSTooltip, XDSPopover

View diff artifacts to review the visual changes.

To accept these changes, comment /update-baselines on this PR.
Baselines will be regenerated and committed automatically.

cixzhang and others added 6 commits February 27, 2026 21:41
Adds XDSPopover — a general-purpose popover built on useXDSLayer.

Features:
- Anchored positioning with 12 placement options
- Click-outside and Escape to dismiss
- Focus management (auto-focus first focusable or heading)
- Entry animation (fade + slide)
- Default padding matching HoverCard
- Accessible: role=dialog, aria-labelledby, focus trap

Co-authored-by: Navi <[email protected]>
Replace placeholder divs with realistic content using XDSHeading,
XDSText, XDSSwitch, XDSCheckboxInput, XDSDivider, etc.

Stories now demonstrate real use cases:
- Settings panel with toggles
- Filter panel with checkboxes and apply/reset
- Confirmation dialog with destructive action
- Hover profile card
- Keyboard shortcuts reference (above placement)
- Remove hover trigger — use XDSHoverCard for hover overlays
- Remove hasFocusTrap prop — always enforce focus trapping
- Remove initialIsShown prop — simplify to controlled/uncontrolled
- Inline ClickPopover — no separate component needed
- Add anchorRef support — sibling-mode rendering (matches XDSTooltip)
- Simplify click handler — delegate to hook's toggle()
- Add explicit color to container — ensure text visibility in top layer
- Remove XDSPopoverTrigger type export
- Update stories: remove HoverTrigger, add AnchorRef, make headings focusable
- Update tests: remove hover test, add anchorRef test

Co-authored-by: Navi <[email protected]>
- Use elevationVars['--elevation-menu'] instead of raw box-shadow string
- Fix toggle bug: guard against light dismiss + click handler race condition
- Default alignment to 'start' instead of 'center' (better mobile behavior)
- CSS position-try-fallbacks already handles flipping when out of viewport

Co-authored-by: Navi <[email protected]>
The :popover-open pseudo-class only matches the element with the
[popover] attribute (rendered by useXDSLayer). The animation styles
(opacity, transform, transitions) were on an inner child div, so
:popover-open never matched and opacity stayed at 0.

Split styles into:
- popoverAnimation: opacity/transform/:popover-open → applied via xstyle
  to the actual popover element (matches useXDSHoverCard pattern)
- container: background/radius/shadow → stays on inner content div

Co-authored-by: Navi <[email protected]>
The popover was anchoring directly to the trigger element (e.g. XDSButton),
which receives :active { transform: scale(0.98) } on press. This caused
the CSS anchor position to shift when clicking to close, producing visible
jitter in the popover position.

Fix: Replace display:contents wrapper with an inline-flex wrapper that
acts as the CSS anchor. The wrapper generates a stable box for anchor
positioning while the trigger element inside it can transform freely
without affecting the anchor position.

Co-authored-by: Navi <[email protected]>
cixzhang and others added 3 commits February 27, 2026 21:41
…ventListener

Keyboard interactions (Enter/Space) weren't working because the popover
was imperatively attaching click handlers to child DOM elements. This
approach bypasses React's event system and can interfere with keyboard
event synthesis.

Fix: Move click handling to a React onClick on the anchor wrapper.
Click events from children (e.g. XDSButton) naturally bubble up to the
wrapper, including keyboard-synthesized clicks from native buttons.

The wrapper now serves two purposes:
1. Stable CSS anchor (inline-flex, no pressed transforms)
2. Click target via React event bubbling

Children are purely about defining the anchor content — no imperative
event listener attachment needed. ARIA attributes still go on the child
element for correct screen reader announcements.

Co-authored-by: Navi <[email protected]>
The popover implements the button + dialog ARIA pattern, so the trigger
must be a <button> or [role="button"]. Previously, click handling was
on the wrapper div (catching all bubbled clicks from any child) and
ARIA attrs were set on firstElementChild regardless of its role.

Changes:
- Add findTriggerButton() helper that finds button/[role="button"]
  either as the element itself or as a descendant
- Both children mode and sibling mode use the same attachTrigger()
  function to apply click/keydown handlers + ARIA attrs to the button
- Add keydown handler for Enter/Space on role="button" elements
  (native <button> already synthesizes click, role="button" does not)
- Remove onClick from wrapper div — it's now on the button directly
- Dev warning when no button is found in children or anchorRef
- New tests: nested button, role="button" ARIA, role="button" click,
  role="button" Enter/Space keyboard, missing button warning

Co-authored-by: Navi <[email protected]>
The tsconfig does not include @types/node, so process is not a known
global. The dev-only guards on console.warn calls caused TS2591 errors
during the DTS generation step.

Removed the environment check — these warnings only fire on actual
misuse (missing button/role=button element), so they're safe to emit
unconditionally.
@cixzhang
cixzhang force-pushed the navi/feat/popover-only branch from 0cf366f to 7d4acb2 Compare February 27, 2026 21:41
@cixzhang
cixzhang added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 11b054e Feb 27, 2026
9 of 10 checks passed
@thedjpetersen
thedjpetersen deleted the navi/feat/popover-only branch March 1, 2026 16:02
cixzhang added a commit that referenced this pull request Apr 26, 2026
* feat(core): add XDSPopover component

Adds XDSPopover — a general-purpose popover built on useXDSLayer.

Features:
- Anchored positioning with 12 placement options
- Click-outside and Escape to dismiss
- Focus management (auto-focus first focusable or heading)
- Entry animation (fade + slide)
- Default padding matching HoverCard
- Accessible: role=dialog, aria-labelledby, focus trap

Co-authored-by: Navi <[email protected]>

* fix(storybook): use real XDS components in Popover stories

Replace placeholder divs with realistic content using XDSHeading,
XDSText, XDSSwitch, XDSCheckboxInput, XDSDivider, etc.

Stories now demonstrate real use cases:
- Settings panel with toggles
- Filter panel with checkboxes and apply/reset
- Confirmation dialog with destructive action
- Hover profile card
- Keyboard shortcuts reference (above placement)

* refactor(core): address popover review feedback

- Remove hover trigger — use XDSHoverCard for hover overlays
- Remove hasFocusTrap prop — always enforce focus trapping
- Remove initialIsShown prop — simplify to controlled/uncontrolled
- Inline ClickPopover — no separate component needed
- Add anchorRef support — sibling-mode rendering (matches XDSTooltip)
- Simplify click handler — delegate to hook's toggle()
- Add explicit color to container — ensure text visibility in top layer
- Remove XDSPopoverTrigger type export
- Update stories: remove HoverTrigger, add AnchorRef, make headings focusable
- Update tests: remove hover test, add anchorRef test

Co-authored-by: Navi <[email protected]>

* fix(core): address round 2 popover review feedback

- Use elevationVars['--elevation-menu'] instead of raw box-shadow string
- Fix toggle bug: guard against light dismiss + click handler race condition
- Default alignment to 'start' instead of 'center' (better mobile behavior)
- CSS position-try-fallbacks already handles flipping when out of viewport

Co-authored-by: Navi <[email protected]>

* fix(core): move popover animation styles to popover element

The :popover-open pseudo-class only matches the element with the
[popover] attribute (rendered by useXDSLayer). The animation styles
(opacity, transform, transitions) were on an inner child div, so
:popover-open never matched and opacity stayed at 0.

Split styles into:
- popoverAnimation: opacity/transform/:popover-open → applied via xstyle
  to the actual popover element (matches useXDSHoverCard pattern)
- container: background/radius/shadow → stays on inner content div

Co-authored-by: Navi <[email protected]>

* fix(popover): use stable anchor wrapper to prevent position jitter

The popover was anchoring directly to the trigger element (e.g. XDSButton),
which receives :active { transform: scale(0.98) } on press. This caused
the CSS anchor position to shift when clicking to close, producing visible
jitter in the popover position.

Fix: Replace display:contents wrapper with an inline-flex wrapper that
acts as the CSS anchor. The wrapper generates a stable box for anchor
positioning while the trigger element inside it can transform freely
without affecting the anchor position.

Co-authored-by: Navi <[email protected]>

* fix(popover): use React onClick on wrapper instead of imperative addEventListener

Keyboard interactions (Enter/Space) weren't working because the popover
was imperatively attaching click handlers to child DOM elements. This
approach bypasses React's event system and can interfere with keyboard
event synthesis.

Fix: Move click handling to a React onClick on the anchor wrapper.
Click events from children (e.g. XDSButton) naturally bubble up to the
wrapper, including keyboard-synthesized clicks from native buttons.

The wrapper now serves two purposes:
1. Stable CSS anchor (inline-flex, no pressed transforms)
2. Click target via React event bubbling

Children are purely about defining the anchor content — no imperative
event listener attachment needed. ARIA attributes still go on the child
element for correct screen reader announcements.

Co-authored-by: Navi <[email protected]>

* fix(popover): target button/role=button for event handlers and ARIA

The popover implements the button + dialog ARIA pattern, so the trigger
must be a <button> or [role="button"]. Previously, click handling was
on the wrapper div (catching all bubbled clicks from any child) and
ARIA attrs were set on firstElementChild regardless of its role.

Changes:
- Add findTriggerButton() helper that finds button/[role="button"]
  either as the element itself or as a descendant
- Both children mode and sibling mode use the same attachTrigger()
  function to apply click/keydown handlers + ARIA attrs to the button
- Add keydown handler for Enter/Space on role="button" elements
  (native <button> already synthesizes click, role="button" does not)
- Remove onClick from wrapper div — it's now on the button directly
- Dev warning when no button is found in children or anchorRef
- New tests: nested button, role="button" ARIA, role="button" click,
  role="button" Enter/Space keyboard, missing button warning

Co-authored-by: Navi <[email protected]>

* fix(popover): remove process.env.NODE_ENV guard that breaks DTS build

The tsconfig does not include @types/node, so process is not a known
global. The dev-only guards on console.warn calls caused TS2591 errors
during the DTS generation step.

Removed the environment check — these warnings only fire on actual
misuse (missing button/role=button element), so they're safe to emit
unconditionally.

---------

Co-authored-by: Navi <[email protected]>
Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* feat(core): add XDSPopover component

Adds XDSPopover — a general-purpose popover built on useXDSLayer.

Features:
- Anchored positioning with 12 placement options
- Click-outside and Escape to dismiss
- Focus management (auto-focus first focusable or heading)
- Entry animation (fade + slide)
- Default padding matching HoverCard
- Accessible: role=dialog, aria-labelledby, focus trap

Co-authored-by: Navi <[email protected]>

* fix(storybook): use real XDS components in Popover stories

Replace placeholder divs with realistic content using XDSHeading,
XDSText, XDSSwitch, XDSCheckboxInput, XDSDivider, etc.

Stories now demonstrate real use cases:
- Settings panel with toggles
- Filter panel with checkboxes and apply/reset
- Confirmation dialog with destructive action
- Hover profile card
- Keyboard shortcuts reference (above placement)

* refactor(core): address popover review feedback

- Remove hover trigger — use XDSHoverCard for hover overlays
- Remove hasFocusTrap prop — always enforce focus trapping
- Remove initialIsShown prop — simplify to controlled/uncontrolled
- Inline ClickPopover — no separate component needed
- Add anchorRef support — sibling-mode rendering (matches XDSTooltip)
- Simplify click handler — delegate to hook's toggle()
- Add explicit color to container — ensure text visibility in top layer
- Remove XDSPopoverTrigger type export
- Update stories: remove HoverTrigger, add AnchorRef, make headings focusable
- Update tests: remove hover test, add anchorRef test

Co-authored-by: Navi <[email protected]>

* fix(core): address round 2 popover review feedback

- Use elevationVars['--elevation-menu'] instead of raw box-shadow string
- Fix toggle bug: guard against light dismiss + click handler race condition
- Default alignment to 'start' instead of 'center' (better mobile behavior)
- CSS position-try-fallbacks already handles flipping when out of viewport

Co-authored-by: Navi <[email protected]>

* fix(core): move popover animation styles to popover element

The :popover-open pseudo-class only matches the element with the
[popover] attribute (rendered by useXDSLayer). The animation styles
(opacity, transform, transitions) were on an inner child div, so
:popover-open never matched and opacity stayed at 0.

Split styles into:
- popoverAnimation: opacity/transform/:popover-open → applied via xstyle
  to the actual popover element (matches useXDSHoverCard pattern)
- container: background/radius/shadow → stays on inner content div

Co-authored-by: Navi <[email protected]>

* fix(popover): use stable anchor wrapper to prevent position jitter

The popover was anchoring directly to the trigger element (e.g. XDSButton),
which receives :active { transform: scale(0.98) } on press. This caused
the CSS anchor position to shift when clicking to close, producing visible
jitter in the popover position.

Fix: Replace display:contents wrapper with an inline-flex wrapper that
acts as the CSS anchor. The wrapper generates a stable box for anchor
positioning while the trigger element inside it can transform freely
without affecting the anchor position.

Co-authored-by: Navi <[email protected]>

* fix(popover): use React onClick on wrapper instead of imperative addEventListener

Keyboard interactions (Enter/Space) weren't working because the popover
was imperatively attaching click handlers to child DOM elements. This
approach bypasses React's event system and can interfere with keyboard
event synthesis.

Fix: Move click handling to a React onClick on the anchor wrapper.
Click events from children (e.g. XDSButton) naturally bubble up to the
wrapper, including keyboard-synthesized clicks from native buttons.

The wrapper now serves two purposes:
1. Stable CSS anchor (inline-flex, no pressed transforms)
2. Click target via React event bubbling

Children are purely about defining the anchor content — no imperative
event listener attachment needed. ARIA attributes still go on the child
element for correct screen reader announcements.

Co-authored-by: Navi <[email protected]>

* fix(popover): target button/role=button for event handlers and ARIA

The popover implements the button + dialog ARIA pattern, so the trigger
must be a <button> or [role="button"]. Previously, click handling was
on the wrapper div (catching all bubbled clicks from any child) and
ARIA attrs were set on firstElementChild regardless of its role.

Changes:
- Add findTriggerButton() helper that finds button/[role="button"]
  either as the element itself or as a descendant
- Both children mode and sibling mode use the same attachTrigger()
  function to apply click/keydown handlers + ARIA attrs to the button
- Add keydown handler for Enter/Space on role="button" elements
  (native <button> already synthesizes click, role="button" does not)
- Remove onClick from wrapper div — it's now on the button directly
- Dev warning when no button is found in children or anchorRef
- New tests: nested button, role="button" ARIA, role="button" click,
  role="button" Enter/Space keyboard, missing button warning

Co-authored-by: Navi <[email protected]>

* fix(popover): remove process.env.NODE_ENV guard that breaks DTS build

The tsconfig does not include @types/node, so process is not a known
global. The dev-only guards on console.warn calls caused TS2591 errors
during the DTS generation step.

Removed the environment check — these warnings only fire on actual
misuse (missing button/role=button element), so they're safe to emit
unconditionally.

---------

Co-authored-by: Navi <[email protected]>
Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* feat(core): add XDSPopover component

Adds XDSPopover — a general-purpose popover built on useXDSLayer.

Features:
- Anchored positioning with 12 placement options
- Click-outside and Escape to dismiss
- Focus management (auto-focus first focusable or heading)
- Entry animation (fade + slide)
- Default padding matching HoverCard
- Accessible: role=dialog, aria-labelledby, focus trap


* fix(storybook): use real XDS components in Popover stories

Replace placeholder divs with realistic content using XDSHeading,
XDSText, XDSSwitch, XDSCheckboxInput, XDSDivider, etc.

Stories now demonstrate real use cases:
- Settings panel with toggles
- Filter panel with checkboxes and apply/reset
- Confirmation dialog with destructive action
- Hover profile card
- Keyboard shortcuts reference (above placement)

* refactor(core): address popover review feedback

- Remove hover trigger — use XDSHoverCard for hover overlays
- Remove hasFocusTrap prop — always enforce focus trapping
- Remove initialIsShown prop — simplify to controlled/uncontrolled
- Inline ClickPopover — no separate component needed
- Add anchorRef support — sibling-mode rendering (matches XDSTooltip)
- Simplify click handler — delegate to hook's toggle()
- Add explicit color to container — ensure text visibility in top layer
- Remove XDSPopoverTrigger type export
- Update stories: remove HoverTrigger, add AnchorRef, make headings focusable
- Update tests: remove hover test, add anchorRef test


* fix(core): address round 2 popover review feedback

- Use elevationVars['--elevation-menu'] instead of raw box-shadow string
- Fix toggle bug: guard against light dismiss + click handler race condition
- Default alignment to 'start' instead of 'center' (better mobile behavior)
- CSS position-try-fallbacks already handles flipping when out of viewport


* fix(core): move popover animation styles to popover element

The :popover-open pseudo-class only matches the element with the
[popover] attribute (rendered by useXDSLayer). The animation styles
(opacity, transform, transitions) were on an inner child div, so
:popover-open never matched and opacity stayed at 0.

Split styles into:
- popoverAnimation: opacity/transform/:popover-open → applied via xstyle
  to the actual popover element (matches useXDSHoverCard pattern)
- container: background/radius/shadow → stays on inner content div


* fix(popover): use stable anchor wrapper to prevent position jitter

The popover was anchoring directly to the trigger element (e.g. XDSButton),
which receives :active { transform: scale(0.98) } on press. This caused
the CSS anchor position to shift when clicking to close, producing visible
jitter in the popover position.

Fix: Replace display:contents wrapper with an inline-flex wrapper that
acts as the CSS anchor. The wrapper generates a stable box for anchor
positioning while the trigger element inside it can transform freely
without affecting the anchor position.


* fix(popover): use React onClick on wrapper instead of imperative addEventListener

Keyboard interactions (Enter/Space) weren't working because the popover
was imperatively attaching click handlers to child DOM elements. This
approach bypasses React's event system and can interfere with keyboard
event synthesis.

Fix: Move click handling to a React onClick on the anchor wrapper.
Click events from children (e.g. XDSButton) naturally bubble up to the
wrapper, including keyboard-synthesized clicks from native buttons.

The wrapper now serves two purposes:
1. Stable CSS anchor (inline-flex, no pressed transforms)
2. Click target via React event bubbling

Children are purely about defining the anchor content — no imperative
event listener attachment needed. ARIA attributes still go on the child
element for correct screen reader announcements.


* fix(popover): target button/role=button for event handlers and ARIA

The popover implements the button + dialog ARIA pattern, so the trigger
must be a <button> or [role="button"]. Previously, click handling was
on the wrapper div (catching all bubbled clicks from any child) and
ARIA attrs were set on firstElementChild regardless of its role.

Changes:
- Add findTriggerButton() helper that finds button/[role="button"]
  either as the element itself or as a descendant
- Both children mode and sibling mode use the same attachTrigger()
  function to apply click/keydown handlers + ARIA attrs to the button
- Add keydown handler for Enter/Space on role="button" elements
  (native <button> already synthesizes click, role="button" does not)
- Remove onClick from wrapper div — it's now on the button directly
- Dev warning when no button is found in children or anchorRef
- New tests: nested button, role="button" ARIA, role="button" click,
  role="button" Enter/Space keyboard, missing button warning


* fix(popover): remove process.env.NODE_ENV guard that breaks DTS build

The tsconfig does not include @types/node, so process is not a known
global. The dev-only guards on console.warn calls caused TS2591 errors
during the DTS generation step.

Removed the environment check — these warnings only fire on actual
misuse (missing button/role=button element), so they're safe to emit
unconditionally.

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

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XDSPopover

3 participants