Repository navigation
feat(Tooltip): a trigger whose tooltip repeats its own text pins without toggle state #9361
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
3
commits into
meta:main
Choose a base branch
from
vjeux:feat/tooltip-own-text-pin
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.
+2,298
−62
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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] 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 | ||
173 changes: 173 additions & 0 deletions
173
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,173 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file TooltipToggleBehaviorA11y.stories.tsx | ||
| * @input Uses Tooltip, 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, and one trigger per | ||
| * `triggerBehavior` value. | ||
| * @position The reproduction path for the `triggerBehavior="toggle"` cases in | ||
| * `packages/core/src/Layer/__tests__/TouchTrigger.a11y.chromium.spec.ts` | ||
| * (`component:Tooltip` 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 {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> | ||
| ), | ||
| }; |
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.
"Astryx clickable rows, cards, and containers ignore the press" does not hold yet: an anchored
role="button"trigger inside an Item row withonClickstill runs the row. Either extend the guard to Item, TreeList and Table rows, or narrow this to the surfaces built onuseClickableContainer'sonClick.