Reproduction for Tooltip conditional-wrap focus loss#8098
Draft
siddharthkp wants to merge 5 commits into
Draft
Conversation
…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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #
Adds two Storybook dev stories under
Components/TooltipV2/Devthat reproduce a keyboard focus-loss accessibility bug and demonstrate two fixes.The bug: conditionally wrapping a
Buttonin aTooltip(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
ConditionalTooltipWrapdev story: reproduces the focus loss (Buggy) and shows two fixes side by side, with a live "current focus" indicator.Tooltipand only change itstext, so the button is never remounted.flushSync. Documents thatTooltipoverrides its child's ref viacloneElement, so the ref must go on theTooltipin the wrapped branch.CheckToActivatedev story: reproduces the same swap driven by checking at least two checkboxes.Changed
Removed
Rollout strategy
Dev-only Storybook stories. No changes to the published
@primer/reactAPI, so no release is needed.Testing & Reviewing
Components/TooltipV2/Dev.ConditionalTooltipWrap, keyboard-focus the first "Save" button and press Enter. Watch the "Current focus" readout drop tobodyin the Buggy row, while Fix A and Fix B keep focus on the button.CheckToActivate, check two items to flip the button from inactive to active and observe the same focus behavior.Merge checklist