Skip to content
Draft
20 changes: 20 additions & 0 deletions .changeset/nested-control-kinds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@astryxdesign/core': patch
---

[fix] A disclosure `<summary>`, an element with `role="menuitemcheckbox"` or `role="menuitemradio"`, and editable text (`contenteditable`) now count as nested controls everywhere Core tells a nested control from its container. A click on one belongs to that control, and a press on one paints only that control:

- `ClickableCard`, `SelectableCard`, `Item` and `TreeList` rows, and `SideNavItem` rows with `actions` or an expand toggle: a click on one inside the row or card no longer runs the row's or card's action, and a mouse, pen or finger press on one no longer darkens the whole row or card. A row whose root is a link still runs and paints.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

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.

SideNavItem belongs in the press half of this sentence only. Its actions and expand toggle are siblings of the row's own link or button, so a click on a summary or a menu checkbox there never ran the row: probed on main and on this revision, the row's onClick stays at 0 calls. Where one of these kinds is reachable inside the row's action, endContent (SideNavItem.tsx:849-850), the row still runs here (1 call). The press half is a real change at this base, since #14303 now routes that row through the shared rule.

- A clickable `Token`: a click on one of these, or on a form control or its label, in `endContent` no longer runs `onClick`, so the click now matches the press, which already left the token unpainted for a form control.
- A `Token` that is both a link and removable: a click on one in `endContent` no longer follows the link or runs `onClick`.
- `TextInput`, `TextArea`, `NumberInput`, `DateTimeInput` and `TimeInput`: a click on one in the field's icon or end slot no longer moves focus to the input.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
- `FieldLabel` with a `ReactNode` description: a click on one in the description no longer reaches the field's control.
- `Overlay` on a touch screen: a tap on one in the media no longer toggles the overlay.
- `Toast`: a swipe that starts on one no longer moves the toast, and F6 moves focus to one when it is the first control in the newest toast.
- `SideNavHeading`: hovering or clicking one in the heading's `icon` no longer opens the heading menu.
- The menu bottom sheet: a press on one in a row's content stays with that control.

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.

The Tokenizer's sheet field changes too and has no line here: a click on one of these kinds inside a custom token no longer opens the sheet (Tokenizer.tsx:2196-2215), which is what the new TokenizerBottomSheet.test.tsx case asserts and what component:Tokenizer FR17 ("a control inside a custom token acts at once") settles. An earlier revision of this note carried that line.

- `Table` row expansion and tree rows: a click on one inside a row no longer expands or collapses the row. A `Table` inside an editable region now expands and toggles its rows on click, since that region is around the table, not a control in the row.
- A sortable `Table` header that holds one now gets the development warning that the header holds its own control.
- The exported `INTERACTIVE_SELECTORS`, `hasInteractiveAncestor`, `useClickableContainer` and `useInputContainer` include them, so a container built on them changes the same way.

@cixzhang
63 changes: 61 additions & 2 deletions apps/storybook/stories/NestedControlPress.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
* TreeList row with an end-content Button, and a Token with a remove
* button, and a standalone Button. A press on the nested control paints
* only that control; a press on the container's own surface paints the
* container
* container. A second story holds an Item row per nested control kind (a
* disclosure summary, a menu checkbox, a menu radio, an editable text box)
* with a count of the row's own runs
* @position Fixture for __tests__/NestedControlPress.a11y.chromium.spec.ts
* and __tests__/NestedControlKinds.a11y.chromium.spec.ts
*/

import type {ReactNode} from 'react';
import {useState, type ReactNode} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {ClickableCard} from '@astryxdesign/core/ClickableCard';
import {SelectableCard} from '@astryxdesign/core/SelectableCard';
Expand Down Expand Up @@ -92,3 +95,59 @@ export const Containers: Story = {
</VStack>
),
};

function KindRow({id, control}: {id: string; control: ReactNode}) {
const [runs, setRuns] = useState(0);
return (
<Case id={id}>
<Item
label="Open row"
onClick={() => setRuns(count => count + 1)}
endContent={control}
/>
<Text type="body" data-testid={`${id}-runs`}>
{`Row ran ${runs}`}
</Text>
</Case>
);
}

export const ControlKinds: Story = {
render: () => (
<VStack gap={4}>
<KindRow
id="summary"
control={
<details>
<summary>Nested</summary>
Details
</details>
}
/>
<KindRow
id="menuitemcheckbox"
control={
<span role="menuitemcheckbox" aria-checked="false" tabIndex={0}>
Nested
</span>
}
/>
<KindRow
id="menuitemradio"
control={
<span role="menuitemradio" aria-checked="false" tabIndex={0}>
Nested
</span>
}
/>
<KindRow
id="contenteditable"
control={
<div role="textbox" contentEditable suppressContentEditableWarning>
Nested
</div>
}
/>
</VStack>
),
};
18 changes: 9 additions & 9 deletions docs/architecture/press-feedback.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions packages/core/src/Field/FieldLabel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,20 @@ describe('FieldLabel', () => {
expect(document.getElementById('ctrl')).toHaveFocus();
});

it('does not forward a click on a disclosure summary in a ReactNode description', async () => {
const user = userEvent.setup();
const onClick = renderWithControl({
description: (
<details>
<summary>Why we ask</summary>
For receipts
</details>
),
});
await user.click(screen.getByText('Why we ask'));
expect(onClick).not.toHaveBeenCalled();
});

it('does NOT forward description clicks for a group label', async () => {
const user = userEvent.setup();
const onClick = renderWithControl({isGroupLabel: true});
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/Layer/useTouchTrigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ describe('tapLandsOnDisabledControl', () => {
[
'<div data-pressable-container="true" aria-disabled="true"><a href="/doc" data-tapped>Doc</a></div>',
],
// A disclosure summary, a menu checkbox or radio, and an editable text
// box are controls too: enabled inside a disabled container, each is
// innermost.
[
'<div data-pressable-container="true" aria-disabled="true"><details><summary data-tapped>Notes</summary></details></div>',
],
[
'<div data-pressable-container="true" aria-disabled="true"><span role="menuitemcheckbox" aria-checked="false"><span data-tapped>Pin</span></span></div>',
],
[
'<div data-pressable-container="true" aria-disabled="true"><span role="menuitemradio" aria-checked="false"><span data-tapped>Pin</span></span></div>',
],
[
'<div data-pressable-container="true" aria-disabled="true"><div contenteditable="true"><span data-tapped>Draft</span></div></div>',
],
// A clickable container that only takes no click (a default Overlay's
// mark) is no disabled control.
[
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/Overlay/Overlay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ describe('Overlay', () => {
});
afterEach(() => restore());

it('does not toggle the hover overlay for a tap on a disclosure summary in its media', () => {
const {container} = render(
<Overlay showOn="hover" content={<span>c</span>} data-testid="hero">
<details>
<summary>Credits</summary>
Photo by Ada
</details>
</Overlay>,
);
fireEvent.click(screen.getByText('Credits'));
expect(getScrim(container).hasAttribute('inert')).toBe(true);
});

it('runs a caller onClick and still toggles the hover overlay on tap', () => {
const onClick = vi.fn((event: {preventDefault: () => void}) => {
event.preventDefault();
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/SideNav/SideNavHeading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,30 @@ describe('SideNavHeading', () => {
expect(openMenuButton()).toHaveAttribute('aria-expanded', 'true');
});

it('does not open the menu on a hover over a disclosure summary in its icon', async () => {
__resetMenuPressForTest();
const user = userEvent.setup();
render(
<SideNavHeading
heading="Acme"
subheading="Account"
icon={
<details>
<summary>Org</summary>
Plan
</details>
}
menu={menu}
/>,
);
// The heading renders its icon in each of its two layouts.
for (const summary of screen.getAllByText('Org')) {
await user.hover(summary);
await afterHoverDelay();
expect(openMenuButton()).toHaveAttribute('aria-expanded', 'false');
}
});

it('treats a heading line whose destination is rejected as a link, not as the trigger area', async () => {
__resetMenuPressForTest();
const user = userEvent.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,18 @@ describe('useTableRowExpansion (detail panel)', () => {
expect(screen.getByTestId('panel')).toHaveTextContent('Ada: Ada bio');
});

it('expands a row on a click when the whole table sits inside an editable region', () => {
// The editable region is around the table, not a control in the row,
// so the row's own click still toggles it.
render(
<div contentEditable suppressContentEditableWarning>
<Harness hasRowClickExpansion />
</div>,
);
fireEvent.click(screen.getByText('Ada'));
expect(screen.getByTestId('panel')).toHaveTextContent('Ada: Ada bio');
});

it('collapses an expanded row when its body is clicked', () => {
render(<Harness hasRowClickExpansion initialExpanded={new Set(['a'])} />);
fireEvent.click(screen.getByText('Ada'));
Expand Down Expand Up @@ -884,6 +896,42 @@ describe('useTableRowExpansion (detail panel)', () => {
expect(screen.queryByTestId('panel')).not.toBeInTheDocument();
});

it.each([
['a disclosure summary', 'summary'],
['a menu checkbox', 'menuitemcheckbox'],
['a menu radio', 'menuitemradio'],
] as const)('yields to %s in a cell', (_name, kind) => {
render(
<Harness
hasRowClickExpansion
columnsOverride={[
{
key: 'name',
header: 'Name',
renderCell: item =>
kind === 'summary' ? (
<details>
<summary data-testid={`control-${item.id}`}>
{item.name}
</summary>
</details>
) : (
<span
role={kind}
aria-checked="false"
tabIndex={0}
data-testid={`control-${item.id}`}>
{item.name}
</span>
),
},
]}
/>,
);
fireEvent.click(screen.getByTestId('control-a'));
expect(screen.queryByTestId('panel')).not.toBeInTheDocument();
});

it('yields to a nested element inside a contenteditable cell', () => {
render(
<Harness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1292,19 +1292,6 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
if (target !== row && hasInteractiveAncestor(target, row)) {
return;
}
// A click inside a contenteditable region is an edit
// action, not a row toggle. The shared guard does not
// include contenteditable (it would change ClickableCard
// and other consumers), so the Table row-click path
// checks it separately.
if (
target !== row &&
target.closest(
'[contenteditable]:not([contenteditable="false"])',
)
) {
return;
}
if (hasTextSelection(row)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,26 @@ describe('useTableSortable — a header that holds its own control', () => {
warn.mockRestore();
});

it('warns for a header that holds a disclosure summary', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
render(
<SortableTable
header={
<details>
<summary>Recent runs</summary>
Last 30 days
</details>
}
/>,
);
expect(
warn.mock.calls.some(call =>
String(call[0]).includes('holds its own control'),
),
).toBe(true);
warn.mockRestore();
});

it('stays silent for a header of plain text', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
render(<SortableTable header="Recent runs" />);
Expand Down
53 changes: 53 additions & 0 deletions packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,59 @@ describe('useTableTreeData — row-click expansion', () => {
expect(screen.queryByText('components')).toBeNull();
});

it.each([
['a disclosure summary', 'summary'],
['a menu checkbox', 'menuitemcheckbox'],
['a menu radio', 'menuitemradio'],
] as const)(
'does not toggle when %s inside the row is clicked',
async (_name, kind) => {
const user = userEvent.setup();
function TreeWithControl() {
const {visibleData, treeConfig} = useTableTreeState<FileRow>({
data: fileTree,
idKey: 'id',
});
const tree = useTableTreeData({
...treeConfig,
hasRowClickExpansion: true,
});
return (
<Table
data={visibleData}
columns={[
{
key: 'name',
header: 'Name',
renderCell: item =>
kind === 'summary' ? (
<details>
<summary data-testid={`control-${item.id}`}>
{item.name}
</summary>
</details>
) : (
<span
role={kind}
aria-checked="false"
tabIndex={0}
data-testid={`control-${item.id}`}>
{item.name}
</span>
),
},
]}
idKey="id"
plugins={{tree}}
/>
);
}
render(<TreeWithControl />);
await user.click(screen.getByTestId('control-src'));
expect(screen.queryByText('components')).toBeNull();
},
);

it('does not toggle when a nested element inside contenteditable is clicked', async () => {
const user = userEvent.setup();
function TreeWithNestedEditable() {
Expand Down
13 changes: 0 additions & 13 deletions packages/core/src/Table/plugins/tree/useTableTreeData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -832,19 +832,6 @@ export function useTableTreeData<T extends Record<string, unknown>>(
if (target !== row && hasInteractiveAncestor(target, row)) {
return;
}
// A click inside a contenteditable region is an edit
// action, not a row toggle. The shared guard does not
// include contenteditable (it would change ClickableCard
// and other consumers), so the Table row-click path
// checks it separately.
if (
target !== row &&
target.closest(
'[contenteditable]:not([contenteditable="false"])',
)
) {
return;
}
if (hasTextSelection(row)) {
return;
}
Expand Down
Loading