Skip to content

fix(Tooltip): under focusTrigger="auto", decide when focus arrives whether it opens the tooltip - #9366

Merged
cixzhang merged 3 commits into
mainfrom
fix/tooltip-auto-focus-roving
Nov 1, 2026
Merged

cixzhang merged 3 commits into
mainfrom
fix/tooltip-auto-focus-roving

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9359.

User impact

Keyboard users lost tooltips on roving-tabindex members. In a Toolbar or ButtonGroup, a Button or IconButton whose tooltip was set after mount (for example, "Show shortcut hints" turned on) never showed its tooltip when the arrow keys reached it. It showed only on mouse hover. The same happened in any caller's roving group that renders tabIndex={-1}, from the first render. A focusable trigger the old check didn't list, such as a <summary>, never opened on keyboard focus either.

Now, under the default focusTrigger="auto", those triggers open on keyboard focus like every other trigger.

Problem and solution fit

  • Cause: useTooltip decided once, when it attached its listeners, whether focus counted: focusTrigger === 'always' || (focusTrigger === 'auto' && isFocusable(el)). isFocusable is false for tabindex="-1", and the decision wasn't revisited when the roving hook later moved the tab stop onto the element.
  • Fix: the focus listeners attach unless focusTrigger is never, and auto decides per event. Focus on the trigger itself counts, since a trigger that receives focus is focusable by definition. Focus inside the trigger counts while the trigger is focusable, which is what the old attach-time check allowed.
  • Blur: the handler remembers whether the arriving focus counted, so its blur hides the tooltip even if the trigger left the tab order in between (a roving hook resets every tabindex before moving focus).
  • Unchanged: a non-focusable wrapper still ignores its children's focus, and their blur doesn't hide a tooltip opened by hover. always and never behave as before. The :focus-visible, touch and modality checks in the focus handler are untouched.

Current specification

component:Tooltip FR4: "Under focusTrigger="auto", focus opens the tooltip on any focusable trigger." The record listed two implementation gaps against that sentence: the tab order read only at attach time, and the narrow list of recognized triggers. Both now hold. This PR:

  • removes those gaps from FR4 and adds "judged when focus arrives";
  • removes the matching Current-state impact bullet ("A roving trigger may not open on focus"), and updates the summary's gap count, the Focus trigger concept row and the verification row to match;
  • names the new cases in FR4's verification line.

The focusTrigger docs (Tooltip prop JSDoc and useTooltip.doc.mjs) now describe what auto does.

Writing rubric results

  • R1 narration: none; the edited FR4 sentence states behavior.
  • R2 research: none.
  • R3 evidence: none in the record.
  • R4 rejected alternatives: none.
  • R5 change references: none.
  • R6 open questions: none.

Evidence

  • Red on main, green here:
    • useTooltip.test.tsx: a trigger that was tabindex="-1" when the tooltip attached opens on keyboard focus after the roving hook moves the stop to it;
    • useTooltip.test.tsx: a <summary> trigger opens on keyboard focus;
    • Tooltip.test.tsx: the issue's repro. A real Toolbar has two IconButtons, the second's tooltip is turned on after mount, and ArrowRight from the first opens the second's tooltip.
  • Red on the previous head, green here: focus that counted inside a focusable container still hides on blur after the container leaves the tab order.
  • Green on both, guarding unchanged behavior: focus inside a non-focusable wrapper doesn't open it, and that child's blur doesn't hide a hover-opened tooltip.
  • Real Chrome 156 against Storybook built from 290d752 (the later commit changes the blur path, records and docs only): every Tooltip, Toolbar, Button and Layer Chromium spec passes (68), including the release-only ones. No story renders a roving member whose tooltip attaches while it isn't the tab stop, so the fix itself is proven by the jsdom cases above. The decision is made on the focus event, not from layout.
  • Tooltip, Toolbar, Button, IconButton, ButtonGroup and Layer suites: 566 passed. tsc for core: clean. pnpm check:knowledge: aligned.

LOC

+233 / −33: about 45 product lines and about 165 test lines.

Scope

  • One change: focusTrigger="auto" judges focus when it arrives.
  • Records: FR4's two auto gaps and the matching Current-state impact bullet removed.
  • Public text contains no internal context.

…ether it opens the tooltip

Tooltip FR4: under auto, focus opens the tooltip on any focusable trigger.
The hook decided once, when it attached its listeners, from the trigger's
tabindex then. A roving-tabindex member that was tabindex="-1" at that moment
(a Toolbar or ButtonGroup Button whose tooltip was set after mount, or a
caller's roving group) never opened on keyboard focus, and a focusable
trigger the check did not list, such as a <summary>, never did either.

The focus listeners now attach unless focusTrigger is never, and auto
decides per event: focus on the trigger itself counts, and focus inside it
counts while the trigger is focusable. A plain wrapper still ignores its
children's focus, and their blur does not hide a hover-opened tooltip.

FR4 drops both auto gaps and the matching Current-state impact bullet.
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 1, 2026 8:25pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 1, 2026
@astracat-bot

astracat-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 1, 2026, 8:36 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026

@astracat-bot astracat-bot Bot 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 requested: the per-event auto check fixes the roving-tabindex case from #9359, and the new tests fail on main and pass here, but it adds one focus-leave regression and leaves four lines describing the old behavior.

  • handleFocusOut re-checks the trigger's focusability at blur, so when a container trigger leaves the tab order while one of its children holds focus, the tooltip never hides. Record in handleFocusIn whether the focus counted, honor that in handleFocusOut, and add a test for it.
  • Update useTooltip.doc.mjs:52 (the dense doc still says "naturally focusable elements only"), Tooltip.spec.md:49 (nine further gaps now, not ten), :191 (drop "(FR4's gap)") and :305-307 (the new auto cases now have focused tests, so they leave the untested list).

[Automated review]

Comment on lines +478 to +486
const handleFocusOut = useCallback(
(e: Event) => {
if (!isFocusForTrigger(e)) {
return;
}
scheduleHide();
},
[isFocusForTrigger, scheduleHide],
);

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.

This re-judges the blur against the trigger's focusability now, not against whether the matching focusin counted. If a focusable container trigger leaves the tab order while one of its children holds focus (useListFocus resets every tabindex before calling focus()), the blur is ignored and the tooltip stays open, contrary to FR4's "Focus leaving the trigger schedules the hide". The base always hid it. One way to fix it:

const focusCountedRef = useRef(false);
// first line of handleFocusIn:
focusCountedRef.current = isFocusForTrigger(e);
// handleFocusOut:
if (!focusCountedRef.current && !isFocusForTrigger(e)) {
  return;
}
focusCountedRef.current = false;
scheduleHide();

Comment on lines +305 to +307
- FR4: `focusTrigger="always"`, `"never"`, and `"auto"` judged when focus
arrives (a roving member that was `tabindex="-1"`, a `<summary>`, and a
non-focusable wrapper whose child takes focus),

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.

These three auto cases now have focused tests in useTooltip.test.tsx, so they no longer belong under "Read from source, with no focused test yet". Keep always and never here and drop the "auto" clause. In the same record, line 49 still counts "ten further implementation gaps" (nine remain beyond press-to-pin), and line 191 still points at "(FR4's gap)" for auto.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 53888b4

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Markdown 149.3 kB (+92 B) · 18.2 kB CSS (0) — — · — · —
Field 46.5 kB (+82 B) · 8.3 kB CSS (0) — — · — · —
Switch 51.6 kB (+79 B) · 9.7 kB CSS (0) — — · — · —
107 more components
Component Size LoC Visual · A11y · RTL
CheckboxInput 53.3 kB (+78 B) · 9.7 kB CSS (0) — — · — · —
RadioList 48.0 kB (+76 B) · 8.3 kB CSS (0) — — · — · —
lab/CommentPin 50.8 kB (+75 B) · 1.2 kB CSS (0) — — · — · —
InputGroup 47.1 kB (+74 B) · 8.4 kB CSS (0) — — · — · —
ContextMenu 78.9 kB (+72 B) · 15.3 kB CSS (0) — — · — · —
TextArea 51.8 kB (+72 B) · 9.8 kB CSS (0) — — · — · —
CheckboxList 48.4 kB (+71 B) · 8.6 kB CSS (0) — — · — · —
DateTimeInput 115.8 kB (+71 B) · 15.6 kB CSS (0) — — · — · —
DateInput 104.0 kB (+70 B) · 15.2 kB CSS (0) — — · — · —
SideNavHeading 62.0 kB (+70 B) · 10.6 kB CSS (0) — — · — · —
TableCell 80.1 kB (+70 B) · 15.7 kB CSS (0) — — · — · —
TableHeaderCell 79.8 kB (+70 B) · 15.5 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 217.5 kB (+69 B) · 454 B CSS (0) — — · — · —
AvatarGroup 42.0 kB (+68 B) · 6.6 kB CSS (0) — — · — · —
Table 88.8 kB (+68 B) · 16.0 kB CSS (0) — — · — · —
AvatarGroupOverflow 42.7 kB (+66 B) · 6.5 kB CSS (0) — — · — · —
Pagination 89.5 kB (+66 B) · 15.8 kB CSS (0) — — · — · —
lab/TransferList 70.8 kB (+65 B) · 1.7 kB CSS (0) — — · — · —
Avatar 39.3 kB (+64 B) · 6.5 kB CSS (0) — — · — · —
lab/ListInput 78.7 kB (+64 B) · 1.6 kB CSS (0) — — · — · —
lab/TransferListSelector 76.4 kB (+64 B) · 1.9 kB CSS (0) — — · — · —
CheckboxListItem 57.9 kB (+63 B) · 11.0 kB CSS (0) — — · — · —
SegmentedControl 41.0 kB (+63 B) · 6.5 kB CSS (0) — — · — · —
SideNavItem 58.2 kB (+63 B) · 10.4 kB CSS (0) — — · — · —
DateRangeInput 73.2 kB (+62 B) · 11.6 kB CSS (0) — — · — · —
Selector 80.9 kB (+62 B) · 15.5 kB CSS (0) — — · — · —
Tooltip · Storybook 18.0 kB (+62 B) · 5.0 kB CSS (0) 604 (+24) ✓ · ✓ · ✓
TopNavHeading 61.4 kB (+62 B) · 10.4 kB CSS (0) — — · — · —
lab/ChatReactionBar 69.4 kB (+62 B) · 1.1 kB CSS (0) — — · — · —
BreadcrumbItem 71.2 kB (+61 B) · 11.4 kB CSS (0) — — · — · —
lab/MobileTokenizer 96.6 kB (+61 B) · 880 B CSS (0) — — · — · —
lab/EmojiPicker 66.7 kB (+60 B) · 722 B CSS (0) — — · — · —
StatusDot 20.2 kB (+59 B) · 6.3 kB CSS (0) — — · — · —
TextInput 57.0 kB (+58 B) · 10.9 kB CSS (0) — — · — · —
TopNavMenu 61.4 kB (+58 B) · 10.5 kB CSS (0) — — · — · —
charts/Chart 67.4 kB (+57 B) · 20 B CSS (0) — — · — · —
BaseTypeahead 58.8 kB (+57 B) · 10.3 kB CSS (0) — — · — · —
MultiSelector 76.8 kB (+57 B) · 15.1 kB CSS (0) — — · — · —
TimeInput 92.4 kB (+57 B) · 14.1 kB CSS (0) — — · — · —
TopNavMegaMenu 57.8 kB (+57 B) · 11.2 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 68.9 kB (+57 B) · 773 B CSS (0) — — · — · —
ListItem 57.3 kB (+56 B) · 11.0 kB CSS (0) — — · — · —
RadioListItem 55.8 kB (+56 B) · 10.1 kB CSS (0) — — · — · —
Thumbnail 53.9 kB (+56 B) · 11.3 kB CSS (0) — — · — · —
Link 46.7 kB (+55 B) · 7.9 kB CSS (0) — — · — · —
Popover 52.8 kB (+55 B) · 12.4 kB CSS (0) — — · — · —
ChatComposer 65.2 kB (+54 B) · 11.2 kB CSS (0) — — · — · —
DialogHeader 52.0 kB (+54 B) · 10.2 kB CSS (0) — — · — · —
TableSelectionToolbar 55.7 kB (+54 B) · 11.5 kB CSS (0) — — · — · —
Carousel 53.6 kB (+53 B) · 10.5 kB CSS (0) — — · — · —
ChatComposerInput 59.8 kB (+53 B) · 10.4 kB CSS (0) — — · — · —
ChatComposerTokenElement 59.8 kB (+53 B) · 10.4 kB CSS (0) — — · — · —
TabMenu 58.7 kB (+53 B) · 10.4 kB CSS (0) — — · — · —
NumberInput 59.2 kB (+52 B) · 11.1 kB CSS (0) — — · — · —
richtext/RichTextEditor 273.3 kB (+52 B) · 2.6 kB CSS (0) — — · — · —
FileInput 57.8 kB (+51 B) · 10.7 kB CSS (0) — — · — · —
Typeahead 66.5 kB (+51 B) · 11.7 kB CSS (0) — — · — · —
AlertDialog 60.0 kB (+50 B) · 12.7 kB CSS (0) — — · — · —
Calendar 58.3 kB (+50 B) · 10.3 kB CSS (0) — — · — · —
richtext/RichTextView 253.8 kB (+50 B) · 2.3 kB CSS (0) — — · — · —
Button 46.2 kB (+49 B) · 9.5 kB CSS (0) — — · — · —
IconButton 46.2 kB (+49 B) · 9.5 kB CSS (0) — — · — · —
Stepper 50.6 kB (+49 B) · 9.9 kB CSS (0) — — · — · —
CodeBlock 63.5 kB (+48 B) · 11.1 kB CSS (0) — — · — · —
lab/TourStep 58.2 kB (+48 B) · 590 B CSS (0) — — · — · —
ChatSendButton 48.9 kB (+47 B) · 9.5 kB CSS (0) — — · — · —
ToggleButton 47.0 kB (+47 B) · 9.6 kB CSS (0) — — · — · —
Lightbox 54.7 kB (+46 B) · 10.1 kB CSS (0) — — · — · —
Slider 51.2 kB (+46 B) · 8.9 kB CSS (0) — — · — · —
Banner 51.0 kB (+45 B) · 10.3 kB CSS (0) — — · — · —
ChatLayout 52.1 kB (+45 B) · 10.3 kB CSS (0) — — · — · —
ComplexSelector 59.8 kB (+45 B) · 11.0 kB CSS (0) — — · — · —
FieldLabel 40.2 kB (+45 B) · 5.9 kB CSS (0) — — · — · —
SideNavCollapseButton 49.9 kB (+45 B) · 9.8 kB CSS (0) — — · — · —
Toast 63.1 kB (+45 B) · 10.1 kB CSS (0) — — · — · —
Tokenizer 73.6 kB (+44 B) · 17.0 kB CSS (0) — — · — · —
DrawerHeader 52.1 kB (+43 B) · 11.6 kB CSS (0) — — · — · —
SideNav 69.6 kB (+43 B) · 10.9 kB CSS (0) — — · — · —
lab/MobilePowerSearch 161.0 kB (+43 B) · 1.2 kB CSS (0) — — · — · —
lab/Schedule 64.2 kB (+43 B) · 3.9 kB CSS (0) — — · — · —
AppShell 72.1 kB (+42 B) · 12.0 kB CSS (0) — — · — · —
MobileNavToggle 49.4 kB (+42 B) · 9.7 kB CSS (0) — — · — · —
ChatLayoutScrollButton 49.6 kB (+41 B) · 9.9 kB CSS (0) — — · — · —
DropdownMenu 76.9 kB (+40 B) · 15.4 kB CSS (0) — — · — · —
LayerProvider 67.2 kB (+40 B) · 10.5 kB CSS (0) — — · — · —
MobileNav 54.4 kB (+40 B) · 10.4 kB CSS (0) — — · — · —
PowerSearch 176.3 kB (+40 B) · 20.4 kB CSS (0) — — · — · —
lab/CommentThread 222.1 kB (+40 B) · 2.4 kB CSS (0) — — · — · —
charts/ChartTooltip 56.7 kB (+39 B) · 20 B CSS (0) — — · — · —
ChatDictationButton 49.6 kB (+39 B) · 9.8 kB CSS (0) — — · — · —
charts/ChartLegend 56.8 kB (+38 B) · 20 B CSS (0) — — · — · —
TopNav 55.3 kB (+37 B) · 10.7 kB CSS (0) — — · — · —
lab/CommentComposer 98.1 kB (+35 B) · 1.9 kB CSS (0) — — · — · —
MoreMenu 77.1 kB (+32 B) · 15.4 kB CSS (0) — — · — · —
lab/InfoTip 23.1 kB (+32 B) · 458 B CSS (0) — — · — · —
lab/Comments 226.8 kB (+30 B) · 2.5 kB CSS (0) — — · — · —
Spinner 25.7 kB (+1 B) · 6.7 kB CSS (0) — — · — · —
Timestamp 28.4 kB (+1 B) · 9.9 kB CSS (0) — — · — · —
ChatMessageList 29.9 kB (0) · 7.9 kB CSS (0) — — · — · —
CommandPalette 54.1 kB (0) · 12.2 kB CSS (0) — — · — · —
CommandPaletteInput 33.7 kB (0) · 8.5 kB CSS (0) — — · — · —
DropdownMenuSubMenu 62.1 kB (0) · 9.9 kB CSS (0) — — · — · —
Heading 7.9 kB (0) · 6.0 kB CSS (0) — — · — · —
ProgressBar 7.9 kB (0) · 6.9 kB CSS (0) — — · — · —
Text 7.4 kB (0) · 6.0 kB CSS (0) — — · — · —
ChatToolCalls 33.0 kB (−1 B) · 9.3 kB CSS (0) — — · — · —
Timer 9.5 kB (−1 B) · 7.0 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 5.69 MB packed (+668 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: core 1 row; run pnpm api:report.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

…val; records say what auto does

CodeBunny on #9366: the blur was judged against the trigger's focusability
at blur time, so a focusable container that left the tab order while a child
held focus kept a focus-opened tooltip open. The handler now remembers
whether the arriving focus counted and hides on its blur either way.

The record's summary gap count, the Focus trigger concept row, the
"no focused test yet" list, the verification row and the hook doc no longer
describe the old attach-time check.

@astracat-bot astracat-bot Bot 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.

Recommend approval: the per-event auto check fixes the roving Toolbar and ButtonGroup case from #9359, the blur now hides whatever focus opened, and the new tests fail without the change and pass with it. The earlier focus-leave regression and the four stale documentation lines are fixed. Before merging, rebase onto main: the branch conflicts in Tooltip.spec.md, where FR11 re-padded the requirement table, and at the end of Tooltip.test.tsx.

[Automated review]

@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 44ded5d

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026
…s-roving

# Conflicts:
#	docs/specs/components/Tooltip/Tooltip.spec.md
#	packages/core/src/Tooltip/Tooltip.test.tsx
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026

@astracat-bot astracat-bot Bot 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.

Recommend approval: the per-event auto check fixes the roving Toolbar and ButtonGroup case from #9359, the blur still hides whatever focus opened, and the new tests fail without the change and pass with it. The merge from main keeps the FR11 rows and tests intact, and the record edit carries a spec approval for this head, so nothing further is needed from the review.

[Automated review]

@cixzhang

cixzhang commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 53888b4

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 1, 2026
@cixzhang
cixzhang merged commit cdab2e6 into main Nov 1, 2026
59 checks passed
@github-actions
github-actions Bot deleted the fix/tooltip-auto-focus-roving branch November 2, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 53888b4e Deployed Nov 1, 2026 by vercel[bot]
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.

[Bug] Tooltip: a trigger with tabindex="-1" when its listeners attach never opens on keyboard focus, so roving toolbar members lose their tooltip

1 participant