Skip to content

fix(HoverCard): focusTrigger="auto" decides when focus arrives, through Tooltip's shared check - #9597

Merged
cixzhang merged 5 commits into
mainfrom
lane4/hovercard-focus-trigger-auto
Nov 3, 2026
Merged

cixzhang merged 5 commits into
mainfrom
lane4/hovercard-focus-trigger-auto

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A keyboard user moves through a toolbar or list with arrow keys (roving tabindex), and one member carries a HoverCard. When that member takes focus, the card doesn't open, though it opens on mouse hover. The same holds for a <summary> or an SVG link used as a trigger. Hover becomes the only way to discover the card, which architecture:interaction-modality INV4 rules out. Tooltip already gets this right.

Problem and solution fit

  • Why does it fail? useHoverCard decided whether to listen for focus at all when its listeners attached: focusTrigger === 'auto' && isFocusable(el). A roving member is tabindex="-1" at that moment, and isFocusable doesn't list <summary> or SVG links. So no focus listener was attached, and nothing changed when the member became the tab stop.
  • Why does it harm the task? The card holds the information the user is navigating to.
  • Why does it matter? Tooltip fixed the same thing by judging focus when it arrives. HoverCard should share that one check rather than keep a second, older copy.

Expected behavior and authority

Smallest restoration

  • Shared check: Tooltip's per-event check and its counted-focus memory move, unchanged, to utils/triggerFocus.ts (isFocusableTrigger, isFocusForTrigger, and createTriggerFocusGate with focusIn/focusOut). Each hook keeps one gate and calls it.
  • useHoverCard:
    • Focus listeners attach unless focusTrigger is "never".
    • Each focusin is judged when it arrives: a trigger that receives focus counts, and focus inside a trigger counts only while the trigger is focusable.
    • A focus that counted still hides on blur, even after the trigger left the tab order.
  • useTooltip: only swaps its local check and memory for the shared gate, with no behavior change. Its tests run unchanged.
  • Record and docs:
    • FR4's gap sentence becomes the behavior (judged when focus arrives), and the Focus trigger row says so.
    • The Current-state bullet is dropped, and the readiness count goes from seven gaps to six.
    • The FR4–FR6 verification row names the new cases.
    • useHoverCard.doc.mjs, HoverCard.doc.mjs (both languages) and the focusTrigger JSDoc use Tooltip's wording.

Evidence

  • Reproduction before the change: a roving trigger that becomes the tab stop, and a <summary> trigger, don't open on focus. Both new cases fail on main.
  • Result after the change: both open. A plain wrapper still ignores focus on its children. A trigger that left the tab order while focused still hides on blur, including when the focus was inside a focusable trigger (which needs the shared memory).
  • Representative unchanged path:
    • Tooltip's suites, including the FR4 roving, <summary>, wrapper and touch-guard cases from the earlier Tooltip fix, pass unchanged.
    • The HoverCard suite passes (145 Tooltip and HoverCard tests).
  • Regression test or other mutation-sensitive proof: reverting useHoverCard fails the roving and <summary> cases.

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.

Testing

  • pnpm vitest run packages/core/src/Tooltip packages/core/src/HoverCard: 145 passed.
  • pnpm check:knowledge: aligned.

Writing rubric results

Run over FR4, the Focus trigger row, Current-state impact, and the FR4–FR6 verification row (docs/contributing/spec-writing.md):

  • Present tense, describes the system: yes. A removed gap bullet, plus named tests.
  • One owner per fact: FR4 states the behavior, worded as Tooltip's FR4 is, and the shared check is cited from the source.
  • Testable: the row names the five cases.

…gh Tooltip's shared check

component:HoverCard Current-state impact ("A roving trigger may not open on
focus"), architecture:interaction-modality INV4. useHoverCard read the tab
order only when its listeners attached, so a roving trigger rendered with
tabindex="-1" never opened on keyboard focus until a re-render, and a
focusable trigger the check does not list (<summary>, an SVG link) never did.

Tooltip already judges focus per event. That check moves to
utils/triggerFocus.ts (isFocusableTrigger, isFocusForTrigger) and both hooks
call it: focus listeners attach unless focusTrigger is "never", each focusin
is judged when it arrives, and a focus that counted still hides on blur
after the trigger left the tab order. Tooltip's behavior and tests are
unchanged. Tests: roving, <summary> (red before), plain wrapper, and
left-the-tab-order. Record: the Current-state bullet is dropped and the
FR4-FR6 row names the cases.
@vercel

vercel Bot commented Nov 2, 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 3, 2026 1:38pm UTC

Request Review

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

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

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

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · f1e8854

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded cancelled. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

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

Requesting changes: the per-event focus check fixes the roving-tabindex and <summary> cases (both new tests fail on main and pass here), and two follow-ups are needed before this lands.

  • The counted-focus memory (focusCountedRef and its blur gate) is now copied in both useHoverCard and useTooltip; please move it into utils/triggerFocus.ts so each hook calls one shared gate.
  • HoverCard.spec.md still states the fixed gap in FR4, the Focus trigger row and the readiness count, and useHoverCard.doc.mjs and the focusTrigger JSDoc still describe attach-time detection; please align them with Tooltip's wording.
  • Optional: the left-the-tab-order test passes without the counted memory, so a case with focus inside a focusable trigger would cover it.

[Automated review]

Comment on lines +407 to +409
// Whether the trigger's current focus counted when it arrived, so its blur
// hides the card even if the trigger has since left the tab order.
const focusCountedRef = useRef(false);

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 counted-focus memory, with its gate at lines 438-441, repeats useTooltip.tsx lines 416-451. Could it move into utils/triggerFocus.ts (for example a small gate with focusIn(event, mode) and focusOut(event, mode)), so both hooks call one owner and a later fix reaches both?

- **Hover timing does not use the shared hover recognizer.** The card runs its
own show and hide timers. `architecture:interaction-modality` INV11 has
`useHoverCard` take its hover timing from the shared hover recognizer.
- **A roving trigger may not open on focus.** Under `focusTrigger="auto"` the

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.

With this bullet gone, FR4 still ends "Implementation gap: under auto the tab order is read only when the trigger's listeners attach … (Current-state impact)", the Focus trigger row still says "(FR4's gap)", and Compatibility/readiness still counts "eight further implementation gaps" (now seven). useHoverCard.doc.mjs lines 14 and 55 and the focusTrigger JSDoc also still describe attach-time detection.

… judges focus when it arrives

CodeBunny on #9597:
- The counted-focus memory moves into utils/triggerFocus.ts as
  createTriggerFocusGate (focusIn, focusOut); useTooltip and useHoverCard
  each keep one gate and call it, with no local copy.
- HoverCard's record drops FR4's gap sentence for the behavior, the Focus
  trigger row says it is judged when focus arrives, and the readiness count
  drops to seven; useHoverCard.doc.mjs, HoverCard.doc.mjs (both languages)
  and the focusTrigger JSDoc use Tooltip's wording.
- A new case covers focus inside a focusable trigger that leaves the tab
  order, which needs the counted memory.
@cixzhang

cixzhang commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 6258aba

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

This looks ready to approve: focusTrigger="auto" now judges focus when it arrives through one shared gate, the new roving and <summary> cases fail on main and pass here, and the earlier requests (shared focus memory, record and docs alignment, the inside-a-focusable-trigger test) are all addressed. Two optional comment cleanups are noted inline.

[Automated review]

Comment on lines +409 to +410
// Under `auto`, whether focus counts is decided when it arrives, and a
// focus that counted still hides on blur (utils/triggerFocus.ts).

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 (INV29): this repeats the JSDoc on isFocusForTrigger and TriggerFocusGate.focusOut in one passive sentence with two topics. Consider deleting it here and at the same lines in useTooltip.tsx.

Comment on lines +558 to +559
// Focus listeners unless focus never opens the card; `auto` decides
// per event (utils/triggerFocus.ts).

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 (INV29): the first clause restates the focusTrigger !== 'never' test below. Keep only the reason, for example "auto judges each focus when it arrives, so every trigger needs the listeners.", and the same in useTooltip.tsx.

…vercard-focus-trigger-auto

# Conflicts:
#	docs/specs/components/HoverCard/HoverCard.spec.md
@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 204a85e

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

This looks ready to approve: under focusTrigger="auto", HoverCard now judges focus when it arrives through the gate it shares with Tooltip, the new roving-tabindex and <summary> cases fail on main and pass here, and the reworded FR4 sentence has an engineering owner's approval for this head.

Optional cleanups:

  • The two comments flagged earlier in useHoverCard.tsx and useTooltip.tsx still restate the code and the shared JSDoc; trimming each to its reason is enough.
  • The description still says the readiness count goes from eight gaps to seven and that the verification row names four cases; at this head it goes from seven to six and the row names five.

[Automated review]

…vercard-focus-trigger-auto

# Conflicts:
#	docs/specs/components/HoverCard/HoverCard.spec.md
@cixzhang

cixzhang commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec f1e8854

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

This looks ready to approve: under focusTrigger="auto", HoverCard now judges focus when it arrives through the gate it shares with Tooltip, the new roving-tabindex and <summary> cases fail without the fix and pass with it, and the reworded FR4 sentence has an engineering owner's approval for this head.

Optional follow-ups:

  • The two comments flagged earlier in useHoverCard.tsx and useTooltip.tsx still restate the code and the shared JSDoc; trimming each to its reason is enough.
  • isFocusableTrigger in utils/triggerFocus.ts keeps its own tag list beside FOCUSABLE_SELECTOR in hooks/focusableSelector.ts; composing the two would leave one focusable model.
  • The description says the readiness count goes from seven gaps to six; at this head the record goes from six to five.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 3, 2026 13:58
@cixzhang
cixzhang merged commit f88f5dc into main Nov 3, 2026
192 of 221 checks passed
@github-actions
github-actions Bot deleted the lane4/hovercard-focus-trigger-auto branch November 4, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — f1e88541 Deployed Nov 3, 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.

1 participant