Skip to content

fix(Tooltip): script focus after a pointer press opens no tooltip on a non-text trigger - #11782

Merged
cixzhang merged 5 commits into
mainfrom
lane4/tooltip-script-focus-after-pointer
Nov 19, 2026
Merged

cixzhang merged 5 commits into
mainfrom
lane4/tooltip-script-focus-after-pointer

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

User impact

After a mouse click or a tap that focused nothing, such as a click on page text or on empty space, an app that then moved focus by script to a button, link or icon button with a Tooltip opened that tooltip, as if the user had tabbed there. The last input was a pointer, so the tooltip covered the control the user was about to use, with no keyboard action behind it. Now a trigger that is not a text field opens nothing in that case. A text-field trigger still opens, and focus after a key press still opens any trigger.

Problem and solution fit

  1. Why it occurs. The tooltip opened on any focus that matched :focus-visible. Browsers mark script focus :focus-visible after a pointer press that focused nothing, so the tooltip opened although the last input was a pointer.
  2. Fix. useTooltip's focus check also reads the document's last input (the shared interaction-modality store). When that input was a pointer and the focused trigger is not a text field, focus opens nothing. Every other path keeps its behavior: a text field, which browsers mark :focus-visible on a pointer's focus; focus after a key press; focus before any input; and the touch rules for a tapped trigger.

Expected behavior and authority

  • component:Tooltip FR4 (current): programmatic focus opens the tooltip "on any other trigger unless the last input was a pointer". FR4 also named this case as an implementation gap; this pull request removes that sentence and its Current-state impact entry.
  • architecture:interaction-modality INV1: a pointer press counts as pointer input for programmatic focus.
  • A text-field trigger after a tap elsewhere keeps opening, as FR4 states for text-entry triggers. component:HoverCard is unchanged: its FR4 opens on any focus, programmatic included.

Smallest restoration

  • packages/core/src/Tooltip/useTooltip.tsx: one check in the focus opener.
  • packages/core/src/Tooltip/useTooltip.tsx: a small private isTextField helper for a text field in any state (read-only, disabled or keyboard-less included). It reads the keyboard module's list of input types that take no text, which keyboardHeight.ts now exports, so the two lists cannot drift.
  • docs/specs/components/Tooltip/Tooltip.spec.md: FR4's gap sentence and the matching Current-state impact entry removed; the gap count goes from nine to eight.
  • A [fix] changeset for @astryxdesign/core.

Evidence

  • Tooltip.test.tsx "script focus after a pointer press that focused nothing": after a mouse press and after a finger press on the page, script focus on a button trigger opens nothing (both fail on main and pass here); script focus on a text-field trigger still opens; a key press after the pointer press still opens a button trigger.
  • The Tooltip, HoverCard, Layer, keyboard, interaction-modality, Toolbar, IconButton and Button suites pass (57 files, 1377 tests), with no type errors, eslint clean and the knowledge check aligned.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

R1 narration: none; the record loses a gap sentence and a Current-state entry and gains nothing.
R2 research: none in the record.
R3 evidence: no record cell names a pull request, issue or commit.
R4 rejected alternatives: none added.
R5 change references: none.
R6 open questions: none added.
R7 project status: none; the gap count is updated to match the entries.

Testing

  • After the main merge (onto 1939759f576) and the helper move: vitest run --project ui packages/core/src/Tooltip packages/core/src/keyboard (13 files, 316 tests), eslint on the changed files, core tsc and pnpm check:knowledge pass.

  • pnpm exec vitest run packages/core/src/Tooltip packages/core/src/HoverCard packages/core/src/Layer packages/core/src/keyboard packages/core/src/utils/interactionModality.test.ts packages/core/src/Toolbar packages/core/src/IconButton packages/core/src/Button: 57 files, 1377 tests pass.

  • tsc --noEmit for @astryxdesign/core: clean. pnpm check:knowledge: aligned.

Overlap checked: #11916, #11831, #11819, #11681, #11452, #11246, #10858, #10720 (each edits useTooltip.tsx, the Tooltip record or its tests for a different change; none changes when focus opens the tooltip. #11831 merges cleanly with this change; #11916, #11819 and #11452 conflict in text with it, so the second to merge resolves; #11681, #11246, #10858 and #10720 already conflict with main)

#11681, which loads the tooltip code after first paint, also edits useTooltip.tsx. Whichever of these lands second merges main.

Owner: fix-loop lane 4. Land path: Drain merges after CodeBunny, Specs and CI, then a device re-take of the tooltip's touch cases after merging main.

…a non-text trigger

After a mouse click or a tap that focused nothing, script focus on a
trigger matched :focus-visible and opened the tooltip, though the last
input was a pointer. A trigger that is not a text field now opens nothing
then. A text field still opens, as browsers mark a pointer's focus on it
focus-visible, and focus after a key press still opens it. Tooltip FR4
no longer lists the gap.
@vercel

vercel Bot commented Nov 14, 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 17, 2026 9:02pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 19, 2026, 10:22 AM UTC

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 14, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 14, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 633eedf

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 14, 2026
@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a794dc8

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
SideNavCollapseButton 67.2 kB (+137 B) · 10.8 kB CSS (0) — — · — · —
DialogHeader 69.2 kB (+135 B) · 12.4 kB CSS (0) — — · — · —
Stepper 68.0 kB (+132 B) · 10.9 kB CSS (0) — — · — · —
132 more components
Component Size LoC Visual · A11y · RTL
DrawerHeader 69.4 kB (+125 B) · 13.8 kB CSS (0) — — · — · —
Banner 68.3 kB (+123 B) · 11.3 kB CSS (0) — — · — · —
MobileNavToggle 66.6 kB (+119 B) · 10.8 kB CSS (0) — — · — · —
ChatDictationButton 66.9 kB (+117 B) · 10.9 kB CSS (0) — — · — · —
CheckboxInput 69.5 kB (+117 B) · 10.2 kB CSS (0) — — · — · —
ChatSendButton 66.7 kB (+115 B) · 10.8 kB CSS (0) — — · — · —
lab/ChatReactionBar 124.0 kB (+113 B) · 1.1 kB CSS (0) — — · — · —
Button 66.3 kB (+112 B) · 10.8 kB CSS (0) — — · — · —
ChatLayoutScrollButton 66.9 kB (+112 B) · 11.0 kB CSS (0) — — · — · —
charts/ChartTooltip 218.6 kB (+110 B) · 451 B CSS (0) — — · — · —
CodeBlock 81.8 kB (+110 B) · 12.2 kB CSS (0) — — · — · —
Calendar 77.4 kB (+108 B) · 11.4 kB CSS (0) — — · — · —
SegmentedControl 102.6 kB (+108 B) · 6.9 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 309.3 kB (+107 B) · 454 B CSS (0) — — · — · —
TableSelectionToolbar 76.6 kB (+106 B) · 14.1 kB CSS (0) — — · — · —
CheckboxList 73.6 kB (+105 B) · 7.8 kB CSS (0) — — · — · —
Carousel 76.4 kB (+104 B) · 11.7 kB CSS (0) — — · — · —
MultiSelector 103.3 kB (+104 B) · 17.8 kB CSS (0) — — · — · —
richtext/RichTextEditor 307.2 kB (+102 B) · 2.6 kB CSS (0) — — · — · —
IconButton 66.3 kB (+101 B) · 10.8 kB CSS (0) — — · — · —
lab/SelectableCardGroup 69.3 kB (+101 B) · 162 B CSS (0) — — · — · —
lab/TabBarMoreList 102.4 kB (+101 B) · 1.8 kB CSS (0) — — · — · —
TopNav 79.3 kB (+100 B) · 11.8 kB CSS (0) — — · — · —
DateTimeInput 226.6 kB (+98 B) · 19.8 kB CSS (0) — — · — · —
Markdown 205.4 kB (+97 B) · 22.1 kB CSS (0) — — · — · —
richtext/RichTextView 283.8 kB (+97 B) · 2.3 kB CSS (0) — — · — · —
Drawer 54.9 kB (+96 B) · 8.5 kB CSS (0) — — · — · —
TopNavMenu 82.9 kB (+96 B) · 12.0 kB CSS (0) — — · — · —
charts/Chart 242.1 kB (+94 B) · 516 B CSS (0) — — · — · —
Link 56.9 kB (+92 B) · 7.1 kB CSS (0) — — · — · —
ListItem 79.5 kB (+90 B) · 12.1 kB CSS (0) — — · — · —
MobileNav 77.5 kB (+90 B) · 11.4 kB CSS (0) — — · — · —
AppShell 98.8 kB (+87 B) · 14.4 kB CSS (0) — — · — · —
CheckboxListItem 80.4 kB (+87 B) · 12.1 kB CSS (0) — — · — · —
lab/Comments 377.0 kB (+87 B) · 2.5 kB CSS (0) — — · — · —
DateInput 203.0 kB (+86 B) · 18.0 kB CSS (0) — — · — · —
InputGroup 61.5 kB (+86 B) · 7.9 kB CSS (0) — — · — · —
Popover 100.2 kB (+86 B) · 15.2 kB CSS (0) — — · — · —
lab/TourStep 95.0 kB (+86 B) · 691 B CSS (0) — — · — · —
Field 59.9 kB (+85 B) · 7.3 kB CSS (0) — — · — · —
Typeahead 89.2 kB (+85 B) · 13.5 kB CSS (0) — — · — · —
lab/Schedule 116.1 kB (+85 B) · 3.9 kB CSS (0) — — · — · —
AvatarGroup 49.1 kB (+84 B) · 5.8 kB CSS (0) — — · — · —
ComplexSelector 78.8 kB (+84 B) · 12.7 kB CSS (0) — — · — · —
FileInput 75.3 kB (+84 B) · 11.7 kB CSS (0) — — · — · —
Selector 114.8 kB (+84 B) · 18.7 kB CSS (0) — — · — · —
Toast 105.5 kB (+84 B) · 11.1 kB CSS (0) — — · — · —
TopNavMegaMenu 77.5 kB (+84 B) · 12.7 kB CSS (0) — — · — · —
lab/TransferList 136.5 kB (+84 B) · 1.2 kB CSS (0) — — · — · —
lab/CommentThread 370.2 kB (+83 B) · 2.4 kB CSS (0) — — · — · —
RadioList 61.2 kB (+82 B) · 7.4 kB CSS (0) — — · — · —
lab/CommentComposer 180.5 kB (+82 B) · 1.9 kB CSS (0) — — · — · —
ChatComposer 85.8 kB (+81 B) · 12.9 kB CSS (0) — — · — · —
PowerSearch 310.3 kB (+81 B) · 25.6 kB CSS (0) — — · — · —
Thumbnail 70.7 kB (+81 B) · 12.4 kB CSS (0) — — · — · —
ContextMenu 103.4 kB (+80 B) · 18.8 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 122.8 kB (+80 B) · 773 B CSS (0) — — · — · —
BreadcrumbItem 98.0 kB (+79 B) · 13.3 kB CSS (0) — — · — · —
SideNavHeading 83.8 kB (+79 B) · 12.1 kB CSS (0) — — · — · —
TopNavHeading 83.4 kB (+79 B) · 12.0 kB CSS (0) — — · — · —
lab/TransferListSelector 145.3 kB (+79 B) · 1.4 kB CSS (0) — — · — · —
SideNavItem 78.2 kB (+77 B) · 11.9 kB CSS (0) — — · — · —
DateRangeInput 100.8 kB (+73 B) · 13.3 kB CSS (0) — — · — · —
SideNav 122.5 kB (+73 B) · 12.2 kB CSS (0) — — · — · —
lab/DiffViewer 94.4 kB (+73 B) · 2.1 kB CSS (0) — — · — · —
DropdownMenu 108.8 kB (+72 B) · 18.9 kB CSS (0) — — · — · —
Table 121.8 kB (+71 B) · 19.8 kB CSS (0) — — · — · —
MoreMenu 109.1 kB (+70 B) · 18.9 kB CSS (0) — — · — · —
TableCell 104.7 kB (+70 B) · 19.3 kB CSS (0) — — · — · —
Avatar 46.3 kB (+67 B) · 5.7 kB CSS (0) — — · — · —
TableHeaderCell 104.5 kB (+66 B) · 19.1 kB CSS (0) — — · — · —
AvatarGroupOverflow 52.3 kB (+65 B) · 5.7 kB CSS (0) — — · — · —
Pagination 147.7 kB (+65 B) · 19.1 kB CSS (0) — — · — · —
TabMenu 80.1 kB (+64 B) · 11.9 kB CSS (0) — — · — · —
lab/ListInput 95.3 kB (+61 B) · 922 B CSS (0) — — · — · —
lab/DialogHeroHeader 90.4 kB (+60 B) · 372 B CSS (0) — — · — · —
Timestamp 30.8 kB (+56 B) · 11.1 kB CSS (0) — — · — · —
lab/CommentPin 60.8 kB (+55 B) · 1.2 kB CSS (0) — — · — · —
FieldLabel 55.8 kB (+53 B) · 5.8 kB CSS (0) — — · — · —
RadioListItem 76.5 kB (+53 B) · 10.7 kB CSS (0) — — · — · —
InfoTip 50.8 kB (+46 B) · 5.4 kB CSS (0) — — · — · —
ChatComposerInput 83.5 kB (+43 B) · 12.1 kB CSS (0) — — · — · —
TextArea 92.6 kB (+43 B) · 9.4 kB CSS (0) — — · — · —
BaseTypeahead 79.6 kB (+42 B) · 11.7 kB CSS (0) — — · — · —
ChatComposerTokenElement 83.5 kB (+42 B) · 12.1 kB CSS (0) — — · — · —
ChatToolCalls 33.8 kB (+42 B) · 8.5 kB CSS (0) — — · — · —
ToggleButton 93.4 kB (+41 B) · 10.9 kB CSS (0) — — · — · —
ChatMessageList 29.5 kB (+39 B) · 7.1 kB CSS (0) — — · — · —
StatusDot 34.2 kB (+37 B) · 5.4 kB CSS (0) — — · — · —
ChatLayout 89.8 kB (+36 B) · 11.4 kB CSS (0) — — · — · —
Heading 13.7 kB (+29 B) · 5.5 kB CSS (0) — — · — · —
Spinner 26.1 kB (+26 B) · 6.3 kB CSS (0) — — · — · —
Tooltip · Storybook 32.5 kB (+26 B) · 4.5 kB CSS (0) 919 (+18) ✓ · ✓ · ✓
Text 13.1 kB (+24 B) · 5.5 kB CSS (0) — — · — · —
NumberInput 104.0 kB (+22 B) · 12.2 kB CSS (0) — — · — · —
TimeInput 177.8 kB (+22 B) · 17.0 kB CSS (0) — — · — · —
Timer 15.3 kB (+18 B) · 6.1 kB CSS (0) — — · — · —
Tokenizer 105.8 kB (+15 B) · 20.4 kB CSS (0) — — · — · —
lab/EmojiPicker 118.7 kB (+15 B) · 751 B CSS (0) — — · — · —
CommandPaletteInput 33.3 kB (+14 B) · 7.6 kB CSS (0) — — · — · —
Slider 114.9 kB (+11 B) · 8.9 kB CSS (0) — — · — · —
lab/LineClamp 15.6 kB (+10 B) · 168 B CSS (0) — — · — · —
DropdownMenuSubMenu 78.9 kB (+8 B) · 10.5 kB CSS (0) — — · — · —
Switch 109.4 kB (+8 B) · 10.0 kB CSS (0) — — · — · —
charts/ChartLegend 48.1 kB (+7 B) · 224 B CSS (0) — — · — · —
CommandPalette 78.5 kB (+6 B) · 12.8 kB CSS (0) — — · — · —
ContextMenuItem 35.9 kB (+5 B) · 7.1 kB CSS (0) — — · — · —
Lightbox 147.8 kB (+4 B) · 12.0 kB CSS (0) — — · — · —
BottomSheet 75.2 kB (0) · 7.8 kB CSS (0) — — · — · —
BottomSheetSwitcher 18.8 kB (0) · 3.4 kB CSS (0) — — · — · —
ButtonGroup 44.3 kB (0) · 3.7 kB CSS (0) — — · — · —
Collapsible 29.2 kB (0) · 4.5 kB CSS (0) — — · — · —
Dialog 25.7 kB (0) · 7.0 kB CSS (0) — — · — · —
DropdownMenuCheckboxItem 28.8 kB (0) · 7.3 kB CSS (0) — — · — · —
DropdownMenuItem 28.0 kB (0) · 6.9 kB CSS (0) — — · — · —
DropdownMenuRadioItem 28.8 kB (0) · 7.3 kB CSS (0) — — · — · —
HoverCard 30.6 kB (0) · 4.5 kB CSS (0) — — · — · —
LayoutPanel 22.1 kB (0) · 5.0 kB CSS (0) — — · — · —
NavHeadingMenu 18.7 kB (0) · 3.5 kB CSS (0) — — · — · —
ResizeHandle 22.3 kB (0) · 4.3 kB CSS (0) — — · — · —
TabList 47.6 kB (0) · 6.5 kB CSS (0) — — · — · —
Toolbar 47.5 kB (0) · 8.2 kB CSS (0) — — · — · —
TopNavMegaMenuFeaturedCard 8.4 kB (0) · 3.6 kB CSS (0) — — · — · —
TopNavMegaMenuItem 15.3 kB (0) · 4.2 kB CSS (0) — — · — · —
TreeList 46.4 kB (0) · 5.9 kB CSS (0) — — · — · —
lab/NavigationScreen 85.2 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/NavigationStack 85.1 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/TabBar 83.7 kB (0) · 1.8 kB CSS (0) — — · — · —
lab/TabBarItem 3.9 kB (0) · 1.8 kB CSS (0) — — · — · —
ProgressBar 12.0 kB (−4 B) · 6.4 kB CSS (0) — — · — · —
TextInput 98.9 kB (−7 B) · 12.0 kB CSS (0) — — · — · —
AlertDialog 129.9 kB (−14 B) · 15.5 kB CSS (0) — — · — · —

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

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.

Accessibility: 1 violation(s)

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

Tooltip - 1 issue(s)
  • 🟠 serious: Ensure elements that have scrollable content are accessible by keyboard in Safari
    • Rule: scrollable-region-focusable · Affects 1/28 stories · Learn more
    • WCAG: 2.1.1, 2.1.3 (Level A)

Generated by PR Enrichment workflow | View full report

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

Approved pending CI: CI has not run on this head yet because the pull request is a draft, and it runs once the pull request is marked ready for review.

The focus check in useTooltip now does what the Tooltip record's FR4 requires: after a mouse click or tap that focused nothing, script focus on a trigger that is not a text field opens no tooltip, while text-field triggers, focus after a key press and hover still open it. The two new negative tests fail on main and pass here, and a Chromium check on the Default story shows the same before and after.

Optional follow-ups, none blocking:

  • List isTextField in the @output line of the keyboardHeight.ts file header.
  • Move "programmatic focus on a text-entry trigger after pointer input opening it" out of the record's "Read from source, with no focused test yet" list, since the new text-field test covers it.
  • Miss: the new comment in useTooltip.tsx (lines 563-565) restates the condition and uses the passive "is excepted"; a shorter active wording is suggested inline.
Claims and files checked

Review mode: same-head; reason: none

  • Changeset: after a click or tap that focused nothing, script focus on a trigger no longer opens the tooltip. Verified: useTooltip.tsx:566-571; the two new negative tests fail on main and pass here; Chromium check on the Default story.
  • Changeset: a text-field trigger still opens. Verified: new text-field test; isTextField exception at useTooltip.tsx:567.
  • Changeset: focus after a key press still opens. Verified: new Tab test; Chromium check with Escape before the script focus opens on both sides.
  • Description: the cause is the :focus-visible-only check plus the browser marking that script focus :focus-visible. Verified: base code; Chromium reports :focus-visible true in that state on both sides.
  • Description: the fix reads the shared last-input store, and text fields, key presses, focus before any input and the touch rules keep their behavior. Verified: interactionModality.ts:67-77, useTooltip.tsx:572; suites pass.
  • Description: the Tooltip record governs, and the pull request removes its gap sentence and Current-state entry, nine gaps to eight. Verified: record diff (only those three text changes); eight entries remain.
  • Description: HoverCard is unchanged and opens on any focus. Verified: HoverCard does not use useTooltip; its record's focus rule.
  • Description: isTextField covers a text field in any state. Verified: keyboardHeight.ts:337-349.
  • Description: 57 test files and 1,377 tests pass, with no type errors, a clean lint and an aligned knowledge check. Verified: same commands at this head.
  • Description: no new public API. Verified: API surface comparison lists no row for Core or the themes; isTextField is not exported from the package.
  • Description: no internal context in public text. Verified.
  • Description: the three overlapping pull requests edit useTooltip.tsx for other changes, and two of them leave the focus rule alone. Verified from their file lists and diffs.
  • Description: the record loses a gap sentence and an entry and gains nothing. Verified.
  • .changeset/tooltip-script-focus-after-pointer.md: clear.
  • docs/specs/components/Tooltip/Tooltip.spec.md: non-blocking note (verification map, line 282).
  • packages/core/src/Tooltip/Tooltip.test.tsx: clear.
  • packages/core/src/Tooltip/useTooltip.tsx: non-blocking note (comment wording, lines 563-565).
  • packages/core/src/keyboard/keyboardHeight.ts: non-blocking note (file header).

Automated review (maintainer link)

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

Copy link
Copy Markdown
Contributor Author

/approve-spec 3aa2def

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 15, 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.

Approved; CI has passed on this head.

The new check in useTooltip's focus opener restores the Tooltip record's FR4: after a mouse click or tap that focused nothing, script focus on a trigger that is not a text field no longer opens the tooltip, while text fields, focus after a key press and hover still open it. The two new negative tests fail without the change and pass with it, and a Chromium run shows the same before and after. There are no blocking findings.

Non-blocking:

  • keyboardHeight.ts lines 9-12: the header's @output list does not name the new isTextField.
  • Tooltip.spec.md line 282: the verification map still lists programmatic focus on a text-entry trigger after pointer input as untested, which the new text-field test now covers.
  • useTooltip.tsx lines 562-564: the new comment restates the condition below it; a shorter reason is suggested inline.
Claims and files checked

Review mode: same-head; reason: none

  • Claim, release note and description: a Tooltip no longer opens when script moves focus to its trigger right after a click or tap that focused nothing. Verified: useTooltip.tsx:565-570; the mouse and finger tests fail without the change and pass with it; Chromium shows the tooltip before and not after.
  • Claim, release note and description: a text-field trigger still opens, since browsers mark a pointer's focus on a text field focus-visible. Verified: the isTextField exception (keyboardHeight.ts:337-349); the text-field test passes; in Chromium a mouse focus on text, read-only, number, date and time inputs matches :focus-visible.
  • Claim, release note and description: focus after a key press still opens any trigger. Verified: the Tab test passes; the store records key presses in the capture phase (interactionModality.ts:143-150); in Chromium, Escape before the script focus opens it before and after.
  • Claim, description: focus before any input and the touch rules keep their behavior. Verified: the store defaults to keyboard (interactionModality.ts:67-71); the touch check at useTooltip.tsx:571 is unchanged; the Tooltip, Layer and touch suites pass.
  • Claim, description: the cause is that browsers mark script focus focus-visible after a pointer press that focused nothing. Verified in Chromium: the button matches :focus-visible in that state.
  • Claim, description: the Tooltip record's FR4 is current and names this case as a gap, and the pull request removes that sentence and its Current-state impact entry, going from nine to eight gaps. Verified: the record has eight Current-state impact entries at this head and nine before; no other requirement text changes.
  • Claim, description: the interaction-modality record counts a pointer press as pointer input for programmatic focus. Verified: its INV1 says programmatic focus keeps the current modality, and its model says a pointer press sets pointer.
  • Claim, description: HoverCard is unchanged and its FR4 opens on any focus. Verified: no HoverCard file changes, and its FR4 says any focus on the trigger opens it.
  • Claim, description: no new public API, visual representation, default or interaction model. Verified: isTextField stays internal, no export, prop or default changes, and CI's API delta lists no rows.
  • Claim, description: the change is one check, one helper, the record edit and a patch-level fix note. Verified against the five changed files.
  • Claim, description: 57 test files and 1,377 tests pass, with no type errors, eslint clean and the knowledge check aligned. Verified by running each.
  • Claim, description: the record edit adds no narration, research, evidence references or project status, and the gap count matches the entries. Verified against the record diff.
  • Claim, description: public text contains no internal context. Verified: no added line, commit message, title or body carries any.
  • Claim, description: three open pull requests also edit useTooltip.tsx. Verified: each is open and lists that file.
  • Claim, description: a device check of the tooltip's touch cases follows the merge. A process note; no record asks for device evidence for this change.
  • .changeset/tooltip-script-focus-after-pointer.md: clear; a patch-level fix note that matches the code.
  • docs/specs/components/Tooltip/Tooltip.spec.md: one non-blocking note (verification map line 282); approval lines unchanged.
  • packages/core/src/Tooltip/Tooltip.test.tsx: clear; four cases pin the fix and its preserved paths.
  • packages/core/src/Tooltip/useTooltip.tsx: one non-blocking comment note; no Effect, listener or ref added.
  • packages/core/src/keyboard/keyboardHeight.ts: one non-blocking header note; the helper stays internal.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 15, 2026 09:44
@duytbp

duytbp commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thanks for this! I ran an independent check on head 3aa2def:

Verdict: approve, with one gap worth closing here or in a follow-up. The fix does what it says: after a mouse, pen or finger press that leaves no key behind, script focus on a non-text trigger opens no tooltip, and a text field, a Tab after the press and focus with no input yet still open it. It doesn't reach the same focus when the person typed into a text field between the press and the script focus, which is the commonest way this bug shows in Chromium. Swapping one call fixes that and keeps every existing test green.

What I ran

Scratch clone, Node 24.22.1, pnpm install --frozen-lockfile, Vitest ui project.

  1. vitest run --project ui packages/core/src/Tooltip/Tooltip.test.tsx packages/core/src/keyboard: 10 files, 205 tests, all pass.
  2. Red check: with useTooltip.tsx reverted to the merge base, the two "opens nothing on a button trigger after a mouse/finger press" cases fail, and the text-field and key-press cases pass. With the head, all four pass.
  3. Edge probes (a scratch test file next to Tooltip.test.tsx, which fakes :focus-visible the same way the PR's tests do). Results on the head:
Case Result
Mouse press on a Close button, then focus handed back to a button trigger stays closed
Pen press on the page, then script focus stays closed
No input yet (page load), then script focus opens
Mouse press, Escape, then script focus opens (keyboard)
Mouse press, then script focus on a checkbox or a link trigger stays closed
Mouse press, then script focus on a search, read-only text, date input or textarea trigger opens (the text-field exception)
Mouse press into a text field, type abc, then script focus on a button trigger opens
The same after a finger press opens
Mouse press, then Shift pressed alone, then script focus opens
  1. Real browsers, plain HTML (Playwright, Chromium 1248 and Firefox 1555): button.matches(':focus-visible') after button.focus() from script.
Before the script focus Chromium Firefox
Click on page text true true
Click into a text field, type abc true false
Click into a text field, no typing false false

Gap: typed text after a press counts as keyboard

opensOnFocus reads getInteractionModality(target) === 'pointer'. A printable key typed into a text field sets the modality to keyboard, so the guard lets the focus through, and Chromium marks that script focus :focus-visible (row 2 of the browser table). The tooltip opens on a focus nobody moved with the keyboard.

Where it shows: a person clicks into a field in a dialog, types, then the app moves focus by script with no further pointer press. Examples are an auto-advancing code input that focuses its submit button, a form that saves on a debounce and hands focus to an action, or an inline editor that commits on a typed separator. This is the PR's own case, a script focus after a pointer interaction, with typing in between.

Minimal repro (jsdom, beside Tooltip.test.tsx, reusing the PR's focusByScript):

it('opens nothing on a button trigger after a mouse press into a field and typing', async () => {
  const onOpenChange = vi.fn();
  render(
    <>
      <input aria-label="Name" />
      <Tooltip content="Save" onOpenChange={onOpenChange} delay={0}>
        <button type="button">Save</button>
      </Tooltip>
    </>,
  );
  const field = screen.getByLabelText('Name');
  fireEvent.pointerDown(field, {pointerType: 'mouse'});
  field.focus();
  for (const key of ['a', 'b', 'c']) fireEvent.keyDown(field, {key});
  focusByScript(screen.getByRole('button', {name: 'Save'}));
  await new Promise(resolve => setTimeout(resolve, 50));
  expect(onOpenChange).not.toHaveBeenCalledWith(true); // fails on 3aa2def20
});

Suggested fix: the module already tracks exactly this. isTextEntrySincePointer stays true after a pointer press while every key since was typed into a text-entry field, and turns false on a navigation key such as Tab. The touch guard (isTouchInteraction in useTouchTrigger.ts) already uses it.

-import {getInteractionModality} from '../utils/interactionModality';
+import {isTextEntrySincePointer} from '../utils/interactionModality';
 ...
       if (
         !isTextField(target) &&
-        getInteractionModality(target) === 'pointer'
+        isTextEntrySincePointer(target)
       ) {

With that change applied to the head, packages/core/src/Tooltip/ passed in full: the PR's four new cases, the rest of the suite, and the two typing probes (mouse and finger). A Tab after the press still opens the tooltip, as the PR's third case shows. One trade-off: Enter counts as text entry, so the guard also holds after a mouse press, typing and Enter in a field. A dialog submitted with Enter that hands focus back to its trigger would then open no tooltip. I think that's the better answer for a submit, but it's a choice, and the Tooltip record should say which way it goes.

Notes (non-blocking)

  • Mouse press then Shift alone: onKeyDown in interactionModality.ts skips only Meta, Alt and Ctrl, so a lone Shift turns the modality to keyboard. Its comment ("holding Shift before a click must not turn that click into keyboard") holds only because the later pointerdown resets it. This predates the PR, and the case is rare.
  • The bot's three nits (the @output header, the verification map row, the comment wording) still apply on this head.
  • CI is green on this head, and the spec is approved for 3aa2def.

Only the tooltip reads it, so keyboardHeight.ts goes back to what main
has. The comment above the check gives the reason only, and the FR4
verification list no longer names the case the text-field test covers.
@cixzhang
cixzhang marked this pull request as draft November 17, 2026 17:20
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 71a6377

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

Not approved yet: the automated review could not complete its checks on this revision, so it read only the diff. An engineering owner can re-run it. As far as the diff shows, the change follows the Tooltip record's FR4, and the record edit has spec-owner approval at this revision.

Needed in this pull request:

  • docs/specs/components/Tooltip/Tooltip.spec.md lines 281-282: removing the case the new text-field test covers left "and not after a finger or pen pressed it" with no subject, so write "programmatic focus on a text-entry trigger not opening it after a finger or pen pressed that trigger when the last input was a pointer press".

Also worth a look:

  • useTooltip.tsx lines 56-67 declare a second NON_TEXT_INPUT_TYPES; if it matches the set keyboard/keyboardHeight.ts already keeps, reuse that one so the two lists cannot drift.
Claims and files checked

Review mode: full; reason: other:source unavailable

  • Release note: no tooltip on script focus right after a pointer press that focused nothing. Matches the guard at useTooltip.tsx:590-597; the tests were not run in this review.
  • Release note: a text-field trigger still opens. Matches the isTextField exception at useTooltip.tsx:74-83; not run.
  • Release note: focus after a key press still opens. Matches the guard, which returns early only after a pointer input; the test at Tooltip.test.tsx:1082-1095 was not run.
  • Description: the helper is private and only the tooltip reads it. Verified: no export at useTooltip.tsx:74.
  • Description: the record loses FR4's gap sentence and its Current-state impact entry, going from nine to eight gaps. The removals are verified in the diff; the count was not checked.
  • Description: the new negative tests fail before the change and pass with it, and the listed suites pass. Not checked: the tests were not run, and CI skipped them on this draft.
  • Description: the interaction-modality record counts a pointer press as pointer input for programmatic focus, and HoverCard is unchanged. HoverCard has no change in the diff; the records were not read.
  • Files: useTooltip.tsx: the guard and helper read, the rest of the file not read. Tooltip.test.tsx: the four new cases read, not run. Tooltip.spec.md: a finding at 281-282 and a note at 51. The changeset: clear.

Automated review (maintainer link)

| End-user impact | Mouse, keyboard, and touch users can each reveal the hint, move onto it, and dismiss it; screen-reader users hear it as the trigger's description. Under the default `touchTrigger="auto"`, a tap on a trigger that performs an action performs only that action. When a button pins it through `show()`, as `component:InfoTip`'s does, people on touch, keyboard, or a screen reader can keep help open to read it, and hear it once when it pins. |
| Builder impact | `touchTrigger` answers one question: is it safe to consume a tap to show this tooltip (DEC-1)? Keep the default `auto` on a trigger that performs an action, pass `tap` where a tap only reveals the tooltip, and pass `none` where a tap must never show it. Help behind an info icon uses `component:InfoTip`; an app's own toggle-style trigger is a button that calls `useTooltip`'s `show()` and `hide()` (DEC-1). The layer is always a scroll container (`overflow-y: auto`), so `position: sticky` and `scroll(nearest)` timelines inside its content resolve against the layer, not the page. |
| Compatibility/readiness | `useTooltip` adds `show` and `hide` (FR12), an additive change. `touchTrigger` keeps its released values and its default `auto`, and pinning adds no public prop. Nine implementation gaps (see Current-state impact). |
| Compatibility/readiness | `useTooltip` adds `show` and `hide` (FR12), an additive change. `touchTrigger` keeps its released values and its default `auto`, and pinning adds no public prop. Eight implementation gaps (see Current-state impact). |

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.

Non-blocking: the gap count has to change whenever a gap closes, and several open pull requests edit this record. "Implementation gaps: see Current-state impact." keeps the pointer without the number.

…nput types

The tooltip and the keyboard module now share one list of input types
that take no text, so the two cannot drift. The FR4 verification line
names its subject again.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a794dc8

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

Approved pending CI: CI is still running on this head, so this is not ready to merge until the required checks pass.

The new check in useTooltip's focus opener restores the Tooltip record's FR4: after a mouse click, pen press or tap that focused nothing, script focus on a trigger that is not a text field no longer opens the tooltip, while text fields, focus after a key press and focus before any input still open it. The two new pointer cases fail without the change and pass with it, and a real-Chromium check shows the same before and after.

  • Non-blocking: the Compatibility row's "Eight implementation gaps" count has to change whenever a gap closes; "Implementation gaps: see Current-state impact." keeps the pointer without the number.
Claims and files checked

Review mode: same-head; reason: none

Claims:

  • Changeset: script focus right after a mouse click or a tap that focused nothing no longer opens the tooltip: verified (the new mouse and finger tests fail on the base and pass here; real-Chromium check).
  • Changeset: a text-field trigger still opens, and focus after a key press still opens: verified (the text-field and key-press tests; the click-then-Escape check is unchanged).
  • Description: the opener used to read :focus-visible alone, and browsers mark script focus after such a press :focus-visible: verified (base useTooltip.tsx; the Chromium probe reports it on both sides).
  • Description: the fix reads the shared last-input store and skips text fields, while focus before any input and the touch rules keep their behavior: verified (useTooltip.tsx:578-585; the store starts at keyboard, interactionModality.ts:67-72; the Tooltip, InfoTip, Layer and HoverCard suites pass).
  • Description: FR4 and the interaction-modality record govern the change, and HoverCard is unchanged: verified against the records on main.
  • Description: the private isTextField covers text fields in any state and reads the keyboard module's exported list, so the two lists cannot drift: verified (useTooltip.tsx:57-71, keyboardHeight.ts:40).
  • Description: the record drops FR4's gap sentence and its Current-state entry, and the gap count goes from nine to eight: verified (it also rewords one verification-list line).
  • Description: a patch fix changeset for core: verified.
  • Description: the new pointer tests fail on main and pass here: verified (2 failed and 2 passed on the base).
  • Description: the Tooltip and keyboard suites pass (13 files, 316 tests) with a clean type check, lint and knowledge check: verified; the wider suite list also passes (58 files, 1455 tests at this head, where the description reports 57 and 1377 from before the main merge).
  • Description: the overlap with eight open Tooltip pull requests, one merging cleanly and three conflicting in text: verified (the three conflicts are in the Tooltip record); main's Tooltip code and record are unchanged since the merge base, and this head merges cleanly into main.

Files:

  • .changeset/tooltip-script-focus-after-pointer.md: clear
  • docs/specs/components/Tooltip/Tooltip.spec.md: one non-blocking note (gap count)
  • packages/core/src/Tooltip/Tooltip.test.tsx: clear
  • packages/core/src/Tooltip/useTooltip.tsx: clear
  • packages/core/src/keyboard/keyboardHeight.ts: clear

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 19, 2026 10:01
@cixzhang
cixzhang merged commit 42190ce into main Nov 19, 2026
154 checks passed
@github-actions
github-actions Bot deleted the lane4/tooltip-script-focus-after-pointer branch November 20, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — a794dc8d Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) 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.

2 participants