Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/36315-card-menu-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/plugin-grid': patch
---

fix(plugin-grid): while a phone list's cards are selecting, Enter or Space on a card's 「⋮」 ticks the card and opens no menu

Clause-②: no
Metadata-protocol: none

On the phone card list, a selection already turned every tap inside a card into a tick. A keyboard still reached the row menu: with focus on a card's 「⋮」 button, Enter, Space or ArrowDown opened it. While selecting, those keys now behave like a tap: Enter and Space tick or untick the card, ArrowDown does nothing, and no menu opens. After 「×」 ends the selection, the same keys open the menu again.
9 changes: 9 additions & 0 deletions ui/packages/plugin-grid/src/ObjectGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,15 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
}
toggleCardRow(row);
}}
// objectstack#36315 — a key is a tap too: the 「⋮」 opens on keydown
// (Enter, Space, ArrowDown), so while selecting the card keeps those
// keys from the controls inside it. Enter and Space still make the
// browser's click, which the capture above turns into a tick.
onKeyDownCapture={(event) => {
if (!cardSelecting || event.target === event.currentTarget) return;
if (!event.currentTarget.contains(event.target as Node)) return;
if (event.key === 'Enter' || event.key === ' ' || event.key === 'ArrowDown') event.stopPropagation();
}}
onPointerDown={(event) => {
const press = longPress.current;
// A fresh press never inherits the last one's flag: a long press
Expand Down
33 changes: 33 additions & 0 deletions ui/packages/plugin-grid/src/__tests__/cardSelection-35883.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,39 @@ describe('a tap on a link inside a card while selecting ticks the card (objectst
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
});

// objectstack#36315 — a keyboard on the 「⋮」 is a tap too: Enter or Space
// ticks the card and opens no menu (nor does ArrowDown); after 「×」 Enter
// opens the menu again.
it.each(['{Enter}', ' '])('while selecting, %s on the card\'s 「⋮」 ticks the card and opens no menu', async (key) => {
const { onRowSelect } = renderLinkedCards();
await mailOf('ada@acme.test');
await startSelecting();
within(await cardOf('Acme')).getByTestId('row-action-trigger').focus();
await userEvent.keyboard(key);
expect(screen.queryByRole('menu')).toBeNull();
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
await userEvent.keyboard('{ArrowDown}');
expect(screen.queryByRole('menu')).toBeNull();
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');

endSelecting();
within(await cardOf('Acme')).getByTestId('row-action-trigger').focus();
await userEvent.keyboard(key);
await waitFor(() => expect(screen.getByRole('menu')).toBeInTheDocument());
});

it('while selecting, Enter on a link inside the card ticks the card and opens nothing', async () => {
const { onRowClick, onRowSelect } = renderLinkedCards();
await mailOf('ada@acme.test');
await startSelecting();
(await mailOf('ada@acme.test')).focus();
await userEvent.keyboard('{Enter}');
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
expect(onRowClick).not.toHaveBeenCalled();
});

it('a long press on the email starts the selection with its card ticked, and the click that ends it opens nothing', async () => {
const { onRowClick, onRowSelect } = renderLinkedCards();
const mail = await mailOf('ada@acme.test');
Expand Down
Loading