Repository navigation
feat(Tooltip, HoverCard, cli): deprecate touchTrigger="tap" (DEP-0016), with its upgrade codemod #9246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vjeux
wants to merge
5
commits into
meta:main
Choose a base branch
from
vjeux:feat/tooltip-touch-trigger-tap-deprecation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,046
−175
Draft
feat(Tooltip, HoverCard, cli): deprecate touchTrigger="tap" (DEP-0016), with its upgrade codemod #9246
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3870f5e
feat(Tooltip): triggerBehavior="toggle" pins the tooltip on a press
vjeux 169e82b
test(Tooltip): triggerBehavior on every input
vjeux f3f40ea
feat(Tooltip): a trigger whose tooltip repeats its own text pins with…
vjeux 26c8977
feat(HoverCard): triggerBehavior="toggle" pins the card on a press
vjeux 2679684
feat(Tooltip, HoverCard, cli): deprecate touchTrigger="tap" (DEP-0016…
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [feat] HoverCard (and `useHoverCard`) take `triggerBehavior` (type `HoverCardTriggerBehavior`): `adaptive`, the default and the released behavior, where hover and focus preview the card and a tap opens it unless the trigger performs an action of its own; `hover`, where hover and focus preview it and touch never opens it; or `toggle`, where hover and focus still preview it and a click, a tap, Enter, or Space on a button trigger pins it open, and the same press closes it. A pinned card stays until Escape, a second press, a press outside, or focus leaving; a press on its own content keeps it, and it takes Escape before the layer beneath it. The press stops at its trigger, so a clickable row, card, or label around it does nothing, and the trigger's own handlers still run. The trigger reports `aria-expanded` and `aria-controls`, and the card's `label` (else its text) is announced once when it pins, inside a modal too (`component:HoverCard` FR9 and FR10). On a trigger that is not a button, a labelled card keeps its own popup state and tap-only opening; `touchTrigger` decides taps only under `adaptive`; `hover` and `toggle` ignore it. | ||
|
|
||
| @vjeux | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [feat] `touchTrigger="tap"` on Tooltip, HoverCard, `useTooltip` and `useHoverCard` is deprecated in favor of `triggerBehavior="toggle"` (DEP-0016); `touchTrigger` remains supported until the next minor; only `"tap"` is deprecated now. It keeps working as released, and beside `triggerBehavior="hover"` or `"toggle"`, `touchTrigger` is ignored. A `tap` call resolves to a `@deprecated` signature, so editors mark it with its replacement, and the docs name it. `astryx upgrade` rewrites static `touchTrigger="tap"` to `triggerBehavior="toggle"` on an icon or span trigger with no `role`, `tabIndex`, event handler, or spread props, and removes static `touchTrigger="auto"` where no props are spread; a rewritten trigger keeps its production behavior, tap-only opening, and in development it logs the warning that only a button trigger pins. Every other `tap` site keeps its prop with a TODO naming the manual migration, and the upgrade lists each one with its file and line among the manual migrations it cannot make: a button, a link, an element with a `role`, `tabIndex`, event handler, or spread props, a trigger whose layer repeats its own text, a `useTooltip` or `useHoverCard` options object, an element it cannot identify, a computed value, or spread props, even beside a static `triggerBehavior="toggle"`. A core codemod reports such a site by passing a `ManualMigrationRequired` to `api.report`, and still keeps its changes to the file. The table-comparison page template now uses the toggle; its modality rail becomes a button so it can pin its explanation. | ||
|
|
||
| @vjeux |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [feat] Tooltip (and `useTooltip`) take `triggerBehavior` (type `TooltipTriggerBehavior`): `adaptive`, the default and the released behavior, where hover and focus preview the tooltip and a tap opens it unless the trigger performs an action of its own; `hover`, where hover and focus preview it and no touch or pen tap opens it; or `toggle`, where hover and focus still preview it and a click, a tap, Enter, or Space on a button trigger pins it open, and the same press closes it. A pinned tooltip stays until Escape, a second press, a press outside, or focus leaving, and it takes Escape before the layer beneath it. The press stops at its trigger, so a clickable row, card, or label around it does nothing, and the trigger's own handlers still run. With `anchorRef`, or `useTooltip` with a caller's trigger, nothing is rendered around the trigger to stop it: the trigger's own `onClick` runs, Astryx clickable rows, cards, and containers ignore the press, and a plain `onClick` element around the trigger receives it unless the trigger's `onClick` stops it. The trigger reports `aria-expanded` and `aria-controls`, and the tooltip's text is announced once when it pins, inside a modal too (`component:Tooltip` FR9 and FR10). A trigger that is not a button gets a development warning and keeps tap-only opening; `touchTrigger` decides taps only under `adaptive`; `hover` and `toggle` ignore it. | ||
|
|
||
| @vjeux |
201 changes: 201 additions & 0 deletions
201
apps/storybook/stories/TooltipToggleBehaviorA11y.stories.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file TooltipToggleBehaviorA11y.stories.tsx | ||
| * @input Uses Tooltip, HoverCard, Button, ClickableCard and Layout from core | ||
| * @output The fixtures the toggle-behavior proofs drive in a real browser: a | ||
| * button whose only job is its tooltip, the same trigger inside a clickable | ||
| * card, an anchored trigger with its own click handler inside a clickable | ||
| * card, a trigger whose tooltip opens on no focus, one trigger per | ||
| * `triggerBehavior` value, and an unlabelled HoverCard of two paragraphs on | ||
| * a button. | ||
| * @position The reproduction path for the `triggerBehavior="toggle"` cases in | ||
| * `packages/core/src/Layer/__tests__/TouchTrigger.a11y.chromium.spec.ts` | ||
| * (`component:Tooltip` FR9, FR10; `component:HoverCard` FR9, FR10; | ||
| * `docs/specs/AST-009/spec.md` FR30: a | ||
| * browser claim is checked against a checked-in story). | ||
| * | ||
| * SYNC: The spec navigates to these story ids by name. Nothing at compile | ||
| * time catches a renamed export — the Chromium spec does, when it finds no | ||
| * story. | ||
| */ | ||
|
|
||
| import {useRef, useState} from 'react'; | ||
| import type {Meta, StoryObj} from '@storybook/react'; | ||
| import {Button} from '@astryxdesign/core/Button'; | ||
| import {ClickableCard} from '@astryxdesign/core/ClickableCard'; | ||
| import {HoverCard} from '@astryxdesign/core/HoverCard'; | ||
| import {VStack} from '@astryxdesign/core/Layout'; | ||
| import {Tooltip} from '@astryxdesign/core/Tooltip'; | ||
|
|
||
| const meta: Meta = { | ||
| title: 'a11y/Tooltip toggle behavior', | ||
| // Driven by the toggle-behavior spec, not photographed: the states under test | ||
| // are pins and closes across presses, which no single frame shows. | ||
| tags: ['no-visual'], | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'A button whose only job is its tooltip takes `triggerBehavior="toggle"`: a click, a tap, Enter, or Space pins the tooltip, and the same press closes it. Inside a clickable card, the press stops at the trigger.', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj; | ||
|
|
||
| /** A press pins the tooltip open; the same press, Escape, or a press outside closes it. */ | ||
| export const ButtonToggle: Story = { | ||
| render: () => ( | ||
| <div style={{padding: 100}}> | ||
| <Tooltip | ||
| content="Rows are ranked by how many places import the icon" | ||
| placement="above" | ||
| triggerBehavior="toggle"> | ||
| <Button label="What is this?" variant="secondary"> | ||
| ? | ||
| </Button> | ||
| </Tooltip> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| function InAClickableCardRender() { | ||
| const [opened, setOpened] = useState(0); | ||
| return ( | ||
| <div style={{padding: 100, maxWidth: 360}}> | ||
| <VStack gap={2}> | ||
| <ClickableCard label="Icon usage" onClick={() => setOpened(n => n + 1)}> | ||
| <VStack gap={2}> | ||
| Icon usage | ||
| <Tooltip | ||
| content="Rows are ranked by how many places import the icon" | ||
| placement="above" | ||
| triggerBehavior="toggle"> | ||
| <Button label="What is this?" variant="secondary"> | ||
| ? | ||
| </Button> | ||
| </Tooltip> | ||
| </VStack> | ||
| </ClickableCard> | ||
| <span>Card opened {opened} times</span> | ||
| </VStack> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** A press on the trigger pins its tooltip and stops there: the card does not open. */ | ||
| export const InAClickableCard: Story = { | ||
| render: () => <InAClickableCardRender />, | ||
| }; | ||
|
|
||
| function AnchoredActionInACardRender() { | ||
| const [opened, setOpened] = useState(0); | ||
| const [pressed, setPressed] = useState(0); | ||
| const anchorRef = useRef<HTMLButtonElement>(null); | ||
| return ( | ||
| <div style={{padding: 100, maxWidth: 360}}> | ||
| <VStack gap={2}> | ||
| <ClickableCard label="Icon usage" onClick={() => setOpened(n => n + 1)}> | ||
| <VStack gap={2}> | ||
| Icon usage | ||
| <Button | ||
| ref={anchorRef} | ||
| label="What is this?" | ||
| variant="secondary" | ||
| onClick={() => setPressed(n => n + 1)}> | ||
| ? | ||
| </Button> | ||
| <Tooltip | ||
| anchorRef={anchorRef} | ||
| content="Rows are ranked by how many places import the icon" | ||
| placement="above" | ||
| triggerBehavior="toggle" | ||
| /> | ||
| </VStack> | ||
| </ClickableCard> | ||
| <span>Card opened {opened} times</span> | ||
| <span>Button pressed {pressed} times</span> | ||
| </VStack> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * An anchored trigger with its own click handler, in a clickable card: the | ||
| * pinning press runs the trigger's own handler, and the card ignores it. | ||
| */ | ||
| export const AnchoredActionInACard: Story = { | ||
| render: () => <AnchoredActionInACardRender />, | ||
| }; | ||
|
|
||
| /** A tooltip that opens on no focus: focus moving to another control still closes a pin. */ | ||
| export const FocusTriggerNever: Story = { | ||
| render: () => ( | ||
| <div style={{padding: 100}}> | ||
| <VStack gap={2}> | ||
| <Tooltip | ||
| content="Rows are ranked by how many places import the icon" | ||
| placement="above" | ||
| triggerBehavior="toggle" | ||
| focusTrigger="never"> | ||
| <Button label="What is this?" variant="secondary"> | ||
| ? | ||
| </Button> | ||
| </Tooltip> | ||
| <Button label="Next" variant="secondary"> | ||
| Next | ||
| </Button> | ||
| </VStack> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| /** One info-only trigger per `triggerBehavior` value: a tap opens, never opens, or pins. */ | ||
| export const TriggerBehaviors: Story = { | ||
| render: () => ( | ||
| <div style={{padding: 100}}> | ||
| <VStack gap={4}> | ||
| <Tooltip content="Adaptive: a tap opens it" triggerBehavior="adaptive"> | ||
| <span tabIndex={0}>Adaptive term</span> | ||
| </Tooltip> | ||
| <Tooltip content="Hover: touch never opens it" triggerBehavior="hover"> | ||
| <span tabIndex={0}>Hover term</span> | ||
| </Tooltip> | ||
| <Tooltip content="Toggle: a press pins it" triggerBehavior="toggle"> | ||
| <Button label="Toggle term" variant="secondary"> | ||
| ? | ||
| </Button> | ||
| </Tooltip> | ||
| </VStack> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| /** | ||
| * An unlabelled card of two paragraphs on a button: a press pins it, its text | ||
| * is announced with the paragraphs apart, and a press on that text, which | ||
| * moves focus to no element, keeps it pinned. | ||
| */ | ||
| export const HoverCardToggle: Story = { | ||
| render: () => ( | ||
| <div style={{padding: 100}}> | ||
| <HoverCard | ||
| content={ | ||
| <> | ||
| <p>Ada Lovelace</p> | ||
| <p>Analyst, Payments</p> | ||
| </> | ||
| } | ||
| placement="below" | ||
| triggerBehavior="toggle"> | ||
| <Button label="Ada" variant="secondary"> | ||
| Ada | ||
| </Button> | ||
| </HoverCard> | ||
| </div> | ||
| ), | ||
| }; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"HoverCard (and
useHoverCard) … The press stops at its trigger, so a clickable row, card, or label around it does nothing" is not true foruseHoverCard: a plain<div onClick>row around a hook trigger receives the pinning press (the hook's JSDoc says so). Scope the sentence to the component and add, as the Tooltip changeset does, that withuseHoverCarda plainonClickelement around the trigger receives the press unless the trigger'sonClickstops it.