Repository navigation
fix(HoverCard): focusTrigger="auto" decides when focus arrives, through Tooltip's shared check - #9597
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
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 (
focusCountedRefand its blur gate) is now copied in bothuseHoverCardanduseTooltip; please move it intoutils/triggerFocus.tsso each hook calls one shared gate. HoverCard.spec.mdstill states the fixed gap in FR4, the Focus trigger row and the readiness count, anduseHoverCard.doc.mjsand thefocusTriggerJSDoc 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]
| // 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
/approve-spec 6258aba |
There was a problem hiding this comment.
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]
| // Under `auto`, whether focus counts is decided when it arrives, and a | ||
| // focus that counted still hides on blur (utils/triggerFocus.ts). |
There was a problem hiding this comment.
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.
| // Focus listeners unless focus never opens the card; `auto` decides | ||
| // per event (utils/triggerFocus.ts). |
There was a problem hiding this comment.
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
|
/approve-spec 204a85e |
There was a problem hiding this comment.
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.tsxanduseTooltip.tsxstill 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
|
/approve-spec f1e8854 |
There was a problem hiding this comment.
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.tsxanduseTooltip.tsxstill restate the code and the shared JSDoc; trimming each to its reason is enough. isFocusableTriggerinutils/triggerFocus.tskeeps its own tag list besideFOCUSABLE_SELECTORinhooks/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]
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, whicharchitecture:interaction-modalityINV4 rules out.Tooltipalready gets this right.Problem and solution fit
useHoverCarddecided whether to listen for focus at all when its listeners attached:focusTrigger === 'auto' && isFocusable(el). A roving member istabindex="-1"at that moment, andisFocusabledoesn't list<summary>or SVG links. So no focus listener was attached, and nothing changed when the member became the tab stop.Expected behavior and authority
component:HoverCardFR4: any focus on the trigger opens it perfocusTrigger. The record lists "A roving trigger may not open on focus" under Current-state impact.architecture:interaction-modalityINV4: hover is never the only discovery path.Smallest restoration
utils/triggerFocus.ts(isFocusableTrigger,isFocusForTrigger, andcreateTriggerFocusGatewithfocusIn/focusOut). Each hook keeps one gate and calls it.focusTriggeris"never".focusinis judged when it arrives: a trigger that receives focus counts, and focus inside a trigger counts only while the trigger is focusable.useHoverCard.doc.mjs,HoverCard.doc.mjs(both languages) and thefocusTriggerJSDoc use Tooltip's wording.Evidence
<summary>trigger, don't open on focus. Both new cases fail on main.<summary>, wrapper and touch-guard cases from the earlier Tooltip fix, pass unchanged.useHoverCardfails the roving and<summary>cases.Scope
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):