Skip to content

Commit 78c6ca5

Browse files
authored
fix(Item): a pointer press on an enabled delegated control that is itself a pressable surface paints the row once, in an enabled row that no swipe holds open (#14034)
* docs(architecture): press feedback has one engine and three recipes * docs(architecture): press feedback review fixes (per-recipe tracking, first-load scope, INV9) * docs(architecture): press feedback states the stretched-control gap on main * docs(architecture): press feedback scopes INV7 to non-activating presses and states INV9 as its own rule * docs(architecture): a stretched control keeps its press paint on its own box * docs(architecture): press feedback scopes drift rules to untracked presses and INV7's failure signal * docs(architecture): press feedback keeps interaction-modality INV13's group and menu tracking owners * docs(architecture): the surface under the finger paints (owner rule); cards stop painting for nested mouse presses * docs(architecture): press feedback names who writes a group press, and scopes INV4's signal to one profile * docs(architecture): the menu profile names useMenuPress's own modules * Merge origin/main * docs: the surface under the finger paints for every pointer in Item, TreeList, Token and the cards; gaps stated * docs: verification rows cover every pointer for nested presses in Item, TreeList and Token * docs: press feedback timing goes through the press-feedback engine (react-component-runtime INV13 reconciled) * docs(press-feedback): name the pen and CheckboxList rows in the nested-press gaps; list only tested cases * Merge remote-tracking branch 'origin/main' into specs/press-feedback-recipes * docs(press-feedback): keep the tested CheckboxList, RadioList and Token Remove cases; scope each gap to what is untested * docs(Token): name the untested end-content press in the FR6 gap * docs(cards): a mouse press keeps desktop timing; where any press paints follows the every-pointer rule * docs(press-feedback): state the owner's paint rule in neutral words * Merge remote-tracking branch 'origin/main' into l0/container-nested-press * docs(press-feedback): Decider line with the decision time * fix(press): a press on a control inside a card, row or token paints only the control, for every pointer A browser applies :active to every ancestor of the pressed element, so a mouse or pen press on a control inside a ClickableCard, SelectableCard, Item row, TreeList row or Token also painted the container. The container rule, which already stopped a finger's press there, now marks the container for a mouse or pen press too: the shared press styles read --_nested-press-paint in their :active arms, and the marked container paints its rest look instead, hover included. Each style resets the property on its own element, so the nested control keeps its own press. press-feedback INV5 states that a key press that activates a control paints its press until release; INV7's gap note goes. Builds on cixzhang's draft in #9930. * Merge remote-tracking branch 'origin/specs/press-feedback-recipes' into l0/container-nested-press * docs(press-feedback): a Space key press paints until release; Enter, which acts on key down, paints none * Merge remote-tracking branch 'origin/main' into l0/container-nested-press # Conflicts: # docs/architecture/press-feedback.md * docs(ClickableCard, SelectableCard, Item, TreeList, Token): the nested-control press gaps close Each record drops its mouse-and-pen gap note, and its verification row names the tests that press a nested control with a finger, a pen and a mouse. The jsdom test adds the finger case for each container. * docs(press-feedback): record that a held Space on a container's own action paints no container press yet Chromium gives a key's :active only to the focused element, so a card's or row's hidden action paints nothing on the container. The readiness row names the gap; the real-browser spec keeps the Button's held-Space guard and leaves the containers' cases to the follow-up. * docs(useClickableContainer, Token): the onPointerDown docs and Token's gap match the shipped nested press * Merge commit 'refs/l1/main-now56' into l1-12231 # Conflicts: # docs/specs/components/ClickableCard/ClickableCard.spec.md # docs/specs/components/SelectableCard/SelectableCard.spec.md # docs/specs/components/Token/Token.spec.md # docs/specs/components/TreeList/TreeList.spec.md * test: the TreeList default-render snapshot takes the shared overlay's new classes * Merge commit 'refs/l1/main-now57' into l1-12231 # Conflicts: # docs/specs/components/Item/Item.spec.md * fix: the nested-press properties are private runtime plumbing; release note and comment wording * Merge main; narrow the nested-press claims to a mouse and a pen; name the rows that keep their press * test: regenerate the TreeList chevron snapshot after the main merge * fix(Item): a press on a read-only input in a row paints no row press, as its click runs no row * docs: the card, TreeList and Token records name the fine-pointer finger gap * docs: the release note names the Item row finger change; wrap the cancelNestedPress comment * docs: scope the Item row press note to coarse-pointer fingers; drop a status sentence * chore: re-run review * docs(TreeList): drop two build-status phrases from rows this change re-pads * fix(Item): a press on the control a row delegates to paints the row once A delegated Link is a pressable surface of its own, so a mouse press painted the row and the Link, and a finger press painted only the Link. The row now marks its delegated control: the press controller paints the row for it, and the control's :active paint gives way to the row's. * docs(Item): FR9 names the delegated-Link press checks; the effect names its external node * chore(press): link the press-delegate owner to its record; drop record citations from comments * chore: changeset for the delegated-control press * fix(press): a disabled delegated control paints nothing; narrow the changeset to pressable-surface delegates; test the Space path * fix(press): a key press on a delegated control stays on the control * Merge remote-tracking branch 'origin/main' into l0/container-nested-press # Conflicts: # docs/specs/components/SelectableCard/SelectableCard.spec.md # docs/specs/components/Token/Token.spec.md * Merge branch 'l0/container-nested-press' into fix/item-delegate-press-row-only * Merge remote-tracking branch 'origin/main' into l0/container-nested-press # Conflicts: # docs/architecture/press-feedback.md # docs/specs/components/ClickableCard/ClickableCard.spec.md # docs/specs/components/Item/Item.spec.md # docs/specs/components/SelectableCard/SelectableCard.spec.md # docs/specs/components/Token/Token.spec.md * docs(press): records and changeset name the Reorder-handle gap and the Item row under a link or button * chore(changeset): bound the Item-under-link sentence to content beside the row's label * docs(press): Item-row sentences bound to rows with their own action; Token's click-and-press gap names any pointer * docs(press): bound INV7 closure to the five containers; Thumbnail and SideNavItem gaps recorded; hook doc names every pointer * fix(press): the nested-press rule holds in another document (isElement); SideNavItem gap names its expand/collapse button * fix(press): TreeList's own-Chevron test holds in another document (isNode); records name the middle-button gap; Token gap names its pointers * fix(press): a mouse or pen press with any button on a nested control turns off the container's press paint * Merge commit 'd8432ac9a037f1da6cef3bfd9d5ea4c0f8242b77' into fix/item-delegate-press-row-only # Conflicts: # docs/specs/components/Item/Item.spec.md # packages/core/src/Item/Item.nestedPress.test.tsx # packages/core/src/hooks/useClickableContainer.ts * Merge remote-tracking branch 'origin/main' into fix/item-delegate-press-row-only # Conflicts: # apps/storybook/stories/NestedControlPress.stories.tsx # docs/specs/components/Item/Item.spec.md # packages/core/src/hooks/useClickableContainer.ts * fix(Item): a delegated control's own press paint gives way only during a mouse or pen press on it, so a Space press keeps its tint * fix(Item): a finger's press on a delegated control also turns off the control's own :active paint, for a touch screen whose primary pointer is fine * test(Item): the mouse-press case name drops 'only'; the finger case below covers the same override
1 parent 19c9194 commit 78c6ca5

11 files changed

Lines changed: 467 additions & 23 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] An `Item` row that delegates with `interactiveRef` to a control that is itself a pressable surface, such as a `Link`, now takes that control's press: a finger or pen press paints the row instead of the control, and the control's own mouse press overlay turns off, so a mouse press shows the row's press once. A disabled row, or a disabled control, keeps the press as before.
6+
7+
@cixzhang

‎apps/storybook/stories/NestedControlPress.stories.tsx‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
* @output One story with each container that holds a nested control: a
88
* ClickableCard and a SelectableCard with a Button, an Item row and a
99
* TreeList row with an end-content Button, and a Token with a remove
10-
* button, and a standalone Button. A press on the nested control paints
11-
* only that control; a press on the container's own surface paints the
10+
* button, a standalone Button, and an Item row that delegates to a Link.
11+
* A press on the nested control paints only that control; a press on the
12+
* container's own surface, or on the control a row delegates to, paints the
1213
* container
1314
* @position Fixture for __tests__/NestedControlPress.a11y.chromium.spec.ts
1415
*/
1516

16-
import type {ReactNode} from 'react';
17+
import {useRef, type ReactNode} from 'react';
1718
import type {Meta, StoryObj} from '@storybook/react';
1819
import {ClickableCard} from '@astryxdesign/core/ClickableCard';
1920
import {SelectableCard} from '@astryxdesign/core/SelectableCard';
2021
import {Item} from '@astryxdesign/core/Item';
22+
import {Link} from '@astryxdesign/core/Link';
2123
import {TreeList} from '@astryxdesign/core/TreeList';
2224
import {Token} from '@astryxdesign/core/Token';
2325
import {Button} from '@astryxdesign/core/Button';
@@ -45,6 +47,21 @@ function NestedButton() {
4547
return <Button label="Nested" size="sm" onClick={() => {}} />;
4648
}
4749

50+
function DelegatingRow() {
51+
const ref = useRef<HTMLAnchorElement>(null);
52+
return (
53+
<Item
54+
label={
55+
<Link ref={ref} href="#change-1">
56+
Change 1
57+
</Link>
58+
}
59+
description="Updated the press rule"
60+
interactiveRef={ref}
61+
/>
62+
);
63+
}
64+
4865
export const Containers: Story = {
4966
render: () => (
5067
<VStack gap={4}>
@@ -86,6 +103,9 @@ export const Containers: Story = {
86103
<Case id="token">
87104
<Token label="Filter token" onClick={() => {}} onRemove={() => {}} />
88105
</Case>
106+
<Case id="item-delegate">
107+
<DelegatingRow />
108+
</Case>
89109
<Case id="button">
90110
<Button label="Standalone" onClick={() => {}} />
91111
</Case>

‎docs/architecture/press-feedback.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ applies_to:
1818
packages/core/src/privateAttributes/pressBox.stylex.ts,
1919
packages/core/src/privateAttributes/pressGroupItem.stylex.ts,
2020
packages/core/src/privateAttributes/pressHeld.stylex.ts,
21+
packages/core/src/privateAttributes/pressDelegate.stylex.ts,
2122
packages/core/src/privateAttributes/pressHoldsDrag.stylex.ts,
2223
packages/core/src/privateAttributes/menuPressLit.stylex.ts,
2324
packages/core/src/hooks/useGroupPressTracking.ts,

‎docs/specs/components/Item/Item.spec.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Consumer migration instructions belong in consumer docs and release notes.
200200
| FR2–FR6 | Real-Chromium geometry assertions over the Item alignment stories | Wrapped label with dot and age; avatar; densities; RTL; theme | A slot center off the first line center by more than 0.5px, or a clipped slot, fails. | `audit:Item/layout` |
201201
| FR8 | `List.test.tsx`, `RadioList.test.tsx`, `CheckboxList.test.tsx` forwarding cases | Each composing row with `align="first-line"` | A row whose Item root lacks `data-align="first-line"` fails. | `audit:Item/api` |
202202
| FR9 | `nestedTouchPress.adopters.test.tsx`; `Item.nestedPress.test.tsx`; the nested-control cases in `CheckboxList.test.tsx`, `RadioList.test.tsx` and `useClickableContainer.test.tsx`; `nestedControlPress.test.tsx`; `NestedControlPress.a11y.chromium.spec.ts`; `Item.test.tsx` "clicks that belong to something else", the form-control-label case, and the List link-row portal case; `useClickableContainer.test.tsx` "a press on a form control's label" | A finger on the delegated control; a finger on another control in the row; a mouse and a pen on another control in a CheckboxList or RadioList row; a finger, a pen and a mouse on another control in an `onClick`, `href` and delegated row; a mouse on a nested control in a link-root row, which paints the row; a click on a role-based control, on a form control's label, or in portaled content | A row painted for a press on another control, or not painted for a press on its delegated control, or an `onClick` or `href` row with no parent-supplied `role` and no link root that runs its `onClick` or follows its link for a click on another control or in portaled content, fails. Gap: no test covers a press on a nested control in a row with a parent-supplied role. Gap: on a device whose primary pointer is fine, a finger press on another control in the row still paints the row (`architecture:press-feedback` INV7 gap). | `audit:Item/behavior` |
203+
| FR9 | `Item.nestedPress.test.tsx` delegated-Link cases; `ItemDelegatedPress.a11y.chromium.spec.ts` | A mouse and a finger on a delegated control that is itself a pressable surface (a Link); a disabled row around one | The delegated control painting a press of its own, the row not painting for a press on it, or a disabled row taking its press, fails. | `audit:Item/behavior` |
203204
| FR10 | `Item.test.tsx` "reflects highlighted, selected, and disabled on the item theme target" | Plain, highlighted only, selected only, disabled only, and all three together | A missing attribute, or an attribute left on a row whose state does not hold, fails. | `audit:Item/theming` |
204205
| AR1, AR2 | Accessibility-tree snapshot of a `first-line` row against a `center` row | Plain and option rows | Any difference in name, role, description, or order fails. | `audit:Item/a11y` |
205206
| PR1 | Source review of Item's alignment styles | All values | A ref, observer, or Effect added for alignment fails review. | `audit:Item/layout` |

‎packages/core/src/Item/Item.nestedPress.test.tsx‎

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* press controller
77
* @output Checks a delegated row's pressed state for a finger: a press on the
88
* control the row delegates to paints the row, since it is the row's
9-
* action; a press on another control inside the row paints none
9+
* action, also when that control is itself a pressable surface (a Link),
10+
* which then paints no press of its own; a press on another control inside
11+
* the row paints none
1012
* @position Testing; validates useClickableContainer's pointerdown callback
1113
* through Item
1214
*/
@@ -16,6 +18,8 @@ import {useRef} from 'react';
1618
import {afterEach, beforeEach, expect, it, vi} from 'vitest';
1719
import {PRESS_ONSET_MS} from '../utils/pressGesture';
1820
import {PRESSED_ATTRIBUTE} from '../utils/pressFeedback';
21+
import {Button} from '../Button/Button';
22+
import {Link} from '../Link/Link';
1923
import {Item} from './Item';
2024

2125
function DelegatingRow() {
@@ -34,6 +38,41 @@ function DelegatingRow() {
3438
);
3539
}
3640

41+
function LinkDelegatingRow({isDisabled = false}: {isDisabled?: boolean}) {
42+
const ref = useRef<HTMLAnchorElement>(null);
43+
return (
44+
<Item
45+
label={
46+
<Link ref={ref} href="#change-1">
47+
Change 1
48+
</Link>
49+
}
50+
interactiveRef={ref}
51+
isDisabled={isDisabled}
52+
/>
53+
);
54+
}
55+
56+
function ButtonDelegatingRow() {
57+
const ref = useRef<HTMLButtonElement>(null);
58+
return (
59+
<Item
60+
label={<Button ref={ref} label="Open" onClick={() => {}} />}
61+
interactiveRef={ref}
62+
/>
63+
);
64+
}
65+
66+
function DisabledButtonDelegatingRow() {
67+
const ref = useRef<HTMLButtonElement>(null);
68+
return (
69+
<Item
70+
label={<Button ref={ref} label="Open" isDisabled onClick={() => {}} />}
71+
interactiveRef={ref}
72+
/>
73+
);
74+
}
75+
3776
function rowOf(element: Element): Element {
3877
const row = element.closest('[data-pressable-container]');
3978
if (row == null) {
@@ -84,6 +123,69 @@ it('keeps the row marked as a pressable container while a finger on another cont
84123
fireEvent.pointerUp(more, {pointerType: 'touch', pointerId: 1});
85124
});
86125

126+
it("paints the row, not the link, for a finger on a delegated Link: the press is the row's action", () => {
127+
render(<LinkDelegatingRow />);
128+
const link = screen.getByRole('link', {name: 'Change 1'});
129+
fingerOn(link);
130+
expect(rowOf(link).getAttribute(PRESSED_ATTRIBUTE)).toBe('on');
131+
expect(link.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
132+
fireEvent.pointerUp(link, {pointerType: 'touch', pointerId: 1});
133+
});
134+
135+
it("turns off a delegated Link's own paint for a mouse press, so the press paints the row once", () => {
136+
render(<LinkDelegatingRow />);
137+
const link = screen.getByRole('link', {name: 'Change 1'});
138+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe('');
139+
fireEvent.pointerDown(link, {pointerType: 'mouse', pointerId: 1});
140+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe(
141+
'var(--_nested-press-rest)',
142+
);
143+
fireEvent.pointerUp(link, {pointerType: 'mouse', pointerId: 1});
144+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe('');
145+
});
146+
147+
it("turns off a delegated Link's own paint for a finger press too, for a touch screen whose primary pointer is fine", () => {
148+
render(<LinkDelegatingRow />);
149+
const link = screen.getByRole('link', {name: 'Change 1'});
150+
fireEvent.pointerDown(link, {pointerType: 'touch', pointerId: 1});
151+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe(
152+
'var(--_nested-press-rest)',
153+
);
154+
fireEvent.pointerUp(link, {pointerType: 'touch', pointerId: 1});
155+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe('');
156+
});
157+
158+
it('leaves a delegated Button its own paint for a Space press where the primary pointer is fine', () => {
159+
expect(window.matchMedia('(pointer: coarse)').matches).toBe(false);
160+
render(<ButtonDelegatingRow />);
161+
const button = screen.getByRole('button', {name: 'Open'});
162+
button.focus();
163+
fireEvent.keyDown(button, {key: ' '});
164+
// The overlay draws `:active` through this property; left unset, a Space
165+
// press paints the button.
166+
expect(button.style.getPropertyValue('--_nested-press-paint')).toBe('');
167+
expect(rowOf(button).hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
168+
fireEvent.keyUp(button, {key: ' '});
169+
});
170+
171+
it('leaves a Link its own press when its row is disabled', () => {
172+
render(<LinkDelegatingRow isDisabled />);
173+
const link = screen.getByRole('link', {name: 'Change 1'});
174+
expect(link.style.getPropertyValue('--_nested-press-paint')).toBe('');
175+
fingerOn(link);
176+
expect(link.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');
177+
fireEvent.pointerUp(link, {pointerType: 'touch', pointerId: 1});
178+
});
179+
180+
it('paints nothing for a finger on a disabled delegated Button in an enabled row', () => {
181+
render(<DisabledButtonDelegatingRow />);
182+
const button = screen.getByRole('button', {name: 'Open'});
183+
fingerOn(button);
184+
expect(rowOf(button).hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
185+
expect(button.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);
186+
fireEvent.pointerUp(button, {pointerType: 'touch', pointerId: 1});
187+
});
188+
87189
function LabelledDelegatingRow() {
88190
const ref = useRef<HTMLInputElement>(null);
89191
return (

‎packages/core/src/Item/Item.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {computeTargetAndRel} from '../Link/computeTargetAndRel';
6666
import {useLinkComponent} from '../Link/useLinkComponent';
6767
import {
6868
cancelNestedPress,
69+
delegatePressToRow,
6970
pressBelongsToControl,
7071
PRESSABLE_CONTAINER_ATTRIBUTE,
7172
useClickableContainerProxy,
@@ -822,6 +823,19 @@ export function Item({
822823
};
823824
});
824825

826+
// Syncs the row's press with the caller's delegated control, a DOM node the
827+
// row does not render and cannot see mount or change. A press on it is the
828+
// row's, so the row paints it and the control does not. On each commit the
829+
// row marks the control while the row takes presses; cleanup frees it, also
830+
// when the ref moves to another node or the row unmounts.
831+
useIsomorphicLayoutEffect(() => {
832+
const control = interactiveRef?.current;
833+
if (!isDelegate || isDisabled || control == null) {
834+
return;
835+
}
836+
return delegatePressToRow(control);
837+
});
838+
825839
// The description element's id, published through ItemDescriptionContext so a
826840
// control Item renders in a slot can point at it with `aria-describedby`.
827841
// `isRenderable` rather than `!= null` so the common empty values — `null`,

0 commit comments

Comments
 (0)