Skip to content

Reproduction for Tooltip conditional-wrap focus loss#8098

Draft
siddharthkp wants to merge 5 commits into
mainfrom
tooltip-focus-loss-repro
Draft

Reproduction for Tooltip conditional-wrap focus loss#8098
siddharthkp wants to merge 5 commits into
mainfrom
tooltip-focus-loss-repro

Conversation

@siddharthkp

Copy link
Copy Markdown
Member

Closes #

Adds two Storybook dev stories under Components/TooltipV2/Dev that reproduce a keyboard focus-loss accessibility bug and demonstrate two fixes.

The bug: conditionally wrapping a Button in a Tooltip (e.g. cond ? <Tooltip><Button/></Tooltip> : <Button/>) swaps the top-level element type at that slot. React reconciles by type per position, so toggling the condition unmounts and recreates the underlying <button>. If that button had keyboard focus when it was activated, focus drops to <body> after the state flip.

Changelog

New

  • ConditionalTooltipWrap dev story: reproduces the focus loss (Buggy) and shows two fixes side by side, with a live "current focus" indicator.
    • Fix A (stable tree): always render the Tooltip and only change its text, so the button is never remounted.
    • Fix B (restore focus): accept the remount and restore focus imperatively via a ref + flushSync. Documents that Tooltip overrides its child's ref via cloneElement, so the ref must go on the Tooltip in the wrapped branch.
  • CheckToActivate dev story: reproduces the same swap driven by checking at least two checkboxes.

Changed

  • None (dev stories only).

Removed

  • None.

Rollout strategy

  • None; if selected, include a brief description as to why

Dev-only Storybook stories. No changes to the published @primer/react API, so no release is needed.

Testing & Reviewing

  1. Run Storybook and open Components/TooltipV2/Dev.
  2. In ConditionalTooltipWrap, keyboard-focus the first "Save" button and press Enter. Watch the "Current focus" readout drop to body in the Buggy row, while Fix A and Fix B keep focus on the button.
  3. In CheckToActivate, check two items to flip the button from inactive to active and observe the same focus behavior.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge
  • (GitHub staff only) Integration tests pass at github/github-ui

…s loss

Adds ConditionalTooltipWrap and CheckToActivate dev stories that reproduce the accessibility focus-loss bug caused by conditionally wrapping a Button in a Tooltip, plus stable-tree and focus-restore fixes.
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6f39d8e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@siddharthkp siddharthkp added the skip changeset This change does not need a changelog label Jul 1, 2026
@github-actions github-actions Bot added the staff Author is a staff member label Jul 1, 2026
@github-actions github-actions Bot temporarily deployed to storybook-preview-8098 July 1, 2026 10:15 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changeset This change does not need a changelog staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant