Skip to content

Commit 729b642

Browse files
fix(plugin-grid): while selecting on a phone, a tap on a link inside a card ticks the card (#36305)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X6okWxYPWAsooBsJoAhnT1u)_ Fixes #36044 Clause-②: no Metadata-protocol: none repo:objectstack#4 · os-project-manager · session_01FEkQ5oK4fFfnLADcipbEeT ## 维护者速读 - 手机上的对象列表进入多选后,点卡片里的邮箱、电话、网址、关联记录名或「⋮」,现在都是勾选或取消这张卡片,不再打开链接;点 × 结束多选后,同样的点击照常打开链接。电脑端表格不变。 - 属于手机端重做(列表卡片与底部浮动选择条)的后续修补,解决多选时误点开链接的问题。 - 出错时手机用户在多选状态下可能点不开卡片里的链接或勾不上卡片;改动只在界面上,撤回这个 PR 即恢复原样,不动任何数据。 - 要你做的:无。 ## What changes `ObjectGrid`'s phone card (`buildMobileCardRenderer`, plugin-grid) gets two capture-phase handlers, so one guard at the card covers every cell renderer instead of an edit per renderer: - `onClickCapture`: while the card list is selecting (or on the click that ends the long press that started the selection), a click whose target is inside the card is cancelled (`preventDefault`, so no `mailto:` / `tel:` / URL follows) and stopped (`stopPropagation`, so no cell handler runs: the referenced record's `openRecord`, the image lightbox, the copy button), and the card is toggled (`toggleCardRow`). Unticking the last card still ends the selection, as before. - `onPointerDownCapture`: while selecting, a pointer-down on a node inside the card (not the card itself) is `preventDefault`ed. The row's 「⋮」 is a Radix `DropdownMenuTrigger`, which opens on pointer-down and skips its handler when the event is already default-prevented; its click then reaches the card's click guard and toggles the card. - Both skip a target outside the card's DOM (a node a portal draws, such as an open menu), which React still bubbles through the card. Every interactive element a card can draw, and what selection mode does with it (all swallowed; none stays live): | Element (renderer) | Opens on | While selecting | |---|---|---| | email `mailto:` anchor (`EmailCellRenderer`) and its copy button | click | toggles the card | | phone `tel:` anchor (`PhoneCellRenderer`) and its copy button | click | toggles the card | | URL anchor (`UrlCellRenderer`) | click | toggles the card | | referenced record chip (`ReferencedRecordLink`: `openRecord` / href) | click | toggles the card | | file link (`FileValueAffordance`), image thumbnail lightbox (`ImageCellRenderer`) | click | toggles the card | | the row's 「⋮」 (`RowActionMenu`, Radix trigger) | pointer-down | opens no menu, toggles the card | | the host's title adornment (`rowAdornment`) | click | toggles the card | The desktop table is not touched: the guard lives only on the phone card. ## Tests New top-level `describe` in the cards' existing selection harness, `plugin-grid/src/__tests__/cardSelection-35883.test.tsx` (AGENTS.md: a new pin for a component with a shared harness file goes into that file), at 390 px with an email and a lookup column, a `RelatedRecordActionsProvider` host and the row's 「⋮」: 1. In selection mode a tap on the email ticks the card and opens nothing (`fireEvent.click` answers false: the default was cancelled); a second tap on the same link unticks it; after 「×」 the same tap opens the link (answers true) and ticks nothing. 2. A tap on the referenced record's chip ticks the card and calls no `openRecord`; after 「×」 it opens the record. 3. A tap on the card's 「⋮」 (`userEvent.click`) opens no menu and ticks the card. 4. A long press on the email starts the selection with the card ticked, and the click that ends the press opens nothing. 5. Control, 1280 px: the table (no cards) keeps its email link and chip live while a row is ticked. Verification readings are in the section below. ## Acceptance notes - Keyboard: Enter on a link inside a selecting card fires a click and toggles the card; Enter or Space on a focused 「⋮」 still opens its menu (Radix opens it on keydown, not on click). The card's own key is unchanged. Not in the card's acceptance (taps); filed #36315. - The 「⋮」 stays drawn while selecting, and a tap on it toggles the card as the ruling says. That is the intended behaviour, not a defect: hiding it while selecting would be a design choice the card does not make. ## Verification All on head 2ed630f (the PR's head; base c30ce97), after building the `@object-ui/plugin-grid` dependency closure (`pnpm --workspace-concurrency=2 --filter "@object-ui/plugin-grid^..." build`, VERDICT command-exit 0). <details><summary>The new pins: green, and red on main (ablations)</summary> `pnpm exec vitest run packages/plugin-grid/src/__tests__/cardSelection-35883.test.tsx` (from `ui/`, under the shared verify lock): - Green: `Tests 13 passed (13)` (8 existing, 5 new). - Ablation 1, the reproduction on main: `ObjectGrid.tsx` as on c30ce97 (marker counts `onClickCapture` 1 to 0, `onPointerDownCapture` 1 to 0): `Tests 4 failed | 9 passed (13)`. The four phone pins fail (email, chip, the 「⋮」, the long press on the email); the desktop control and the 8 existing tests pass. - Ablation 2, only the pointer-down guard removed (`scripts/ablation-replace.mjs`, anchor 1 to 0, blob 4fe1c05 to 5f73c210): `Tests 1 failed | 12 passed (13)`, the 「⋮」 pin alone. - Each leg restored with `git checkout HEAD`, proven by the file's hash equal to the HEAD blob (4fe1c05) and an empty `git diff HEAD`; green again after: `13 passed (13)`. - The test imports `../ObjectGrid` from source, so no `dist/` sits between the mutation and the run. </details> <details><summary>Package and gates</summary> - `pnpm exec vitest run packages/plugin-grid/` (from `ui/`): `Test Files 300 passed (300)`, `Tests 2654 passed (2654)`, exit 0. - `pnpm run type-check` in `ui/packages/plugin-grid` (`tsc --noEmit && tsc -p tsconfig.test.json`; the second project compiles the tests): exit 0. - eslint on the two changed files: 0 errors; warnings equal to main's `ObjectGrid.tsx` (145 both). - `node scripts/pm/dispatch-gates.mjs --commands` derived 39 families for this diff; all 39 run locally, each exit 0 (`pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped). `--ran` reconciliation: "39 derived famil(ies) accounted for — 39 run, 0 NOT-MEASURED (a DERIVED zero)". - `node scripts/pm/overlap-check.mjs --branch=claude/issue-36044-phone-select-taps`: VERDICT clean. - The full farm (Lint UI, Test UI and the rest) is CI's. </details> Two-minute check: run the first command above; expect `13 passed`. In a browser at 390 px, on a list that shows an email column, 「⋮ More」 then 「Select」, tap an email: the card ticks and no mail app opens; tap 「×」, tap the email again: it opens. Read first, by risk: `ui/packages/plugin-grid/src/ObjectGrid.tsx` (the two capture handlers on the card, `onClickCapture` and `onPointerDownCapture`), then the new `describe` in `cardSelection-35883.test.tsx`. --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5oK4fFfnLADcipbEeT)_ <!-- signed: repo:objectstack#4 · os-project-manager · session_01FEkQ5oK4fFfnLADcipbEeT --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 740720c commit 729b642

3 files changed

Lines changed: 199 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
---
4+
5+
fix(grid): on a phone's card list, while a selection is open, a tap on a link inside a card ticks or unticks the card
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A tap on a card's email, phone number, URL, referenced record, image, copy button or 「⋮」 used to open the link, the record or the menu instead of ticking the card. While a selection is open the card now takes every tap inside it, as phone apps do in selection mode; the click that ends the long press which starts a selection opens nothing either. When the selection ends, the same taps open their links again. The desktop table is unchanged.

‎ui/packages/plugin-grid/src/ObjectGrid.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,32 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
42134213
(rowOpensRecord !== false || cardSelecting) && 'cursor-pointer hover:bg-accent/50',
42144214
cardSelected && 'border-primary bg-primary/5',
42154215
)}
4216+
// objectstack#36044 — while a selection is open the card owns every tap
4217+
// inside it: a tap on a link, a referenced record's chip, an image or
4218+
// a button the card draws ticks or unticks the card and opens nothing,
4219+
// as phone apps do in selection mode. The cells stop their own clicks
4220+
// from reaching the card, so the card takes them first, in the capture
4221+
// phase. The row's 「⋮」 opens on pointer-down, which the card cancels
4222+
// first. The click that ends the long press that started the selection
4223+
// is swallowed here too, whatever it landed on. A node a portal draws
4224+
// (an open menu) is not the card's.
4225+
onPointerDownCapture={(event) => {
4226+
if (!cardSelecting || event.target === event.currentTarget) return;
4227+
if (!event.currentTarget.contains(event.target as Node)) return;
4228+
event.preventDefault();
4229+
}}
4230+
onClickCapture={(event) => {
4231+
const press = longPress.current;
4232+
if (!cardSelecting && !press.fired) return;
4233+
if (!event.currentTarget.contains(event.target as Node)) return;
4234+
event.preventDefault();
4235+
event.stopPropagation();
4236+
if (press.fired) {
4237+
press.fired = false;
4238+
return;
4239+
}
4240+
toggleCardRow(row);
4241+
}}
42164242
onPointerDown={(event) => {
42174243
const press = longPress.current;
42184244
// A fresh press never inherits the last one's flag: a long press

‎ui/packages/plugin-grid/src/__tests__/cardSelection-35883.test.tsx‎

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
*/
2424
import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
2525
import { render, cleanup, fireEvent, waitFor, screen, within, act } from '@testing-library/react';
26+
import userEvent from '@testing-library/user-event';
2627
import '@testing-library/jest-dom';
2728
import React from 'react';
2829

2930
import { ObjectGrid } from '../ObjectGrid';
3031
import { requestListSelection, useListPageSelectable } from '../listPageScope';
31-
import { ActionProvider, SchemaRendererProvider } from '@object-ui/react';
32+
import {
33+
ActionProvider,
34+
RelatedRecordActionsProvider,
35+
SchemaRendererProvider,
36+
type RelatedRecordActionsValue,
37+
} from '@object-ui/react';
3238
import { registerAllFields } from '@object-ui/fields';
3339

3440
beforeAll(() => {
@@ -221,6 +227,162 @@ describe('card list selection on a phone (objectstack#35883)', () => {
221227
});
222228
});
223229

230+
/**
231+
* objectstack#36044 — while a selection is open, every tap on a card ticks or
232+
* unticks it, a tap on a link the card draws included: the email, the
233+
* referenced record's chip and the row's 「⋮」 open nothing. When the selection
234+
* ends, the same taps open again.
235+
*/
236+
describe('a tap on a link inside a card while selecting ticks the card (objectstack#36044)', () => {
237+
const LINKED_ROWS = [
238+
{ id: 'a1', name: 'Acme', email: 'ada@acme.test', owner: { id: 'u9', name: 'Grace' } },
239+
{ id: 'a2', name: 'Globex', email: 'hank@globex.test', owner: { id: 'u8', name: 'Linus' } },
240+
];
241+
const opened: Array<[string, string | number]> = [];
242+
const host: RelatedRecordActionsValue = {
243+
resolve: () => ({}),
244+
recordHref: (objectName, recordId) => `/apps/demo/${objectName}/record/${encodeURIComponent(String(recordId))}`,
245+
openRecord: (objectName, recordId) => { opened.push([objectName, recordId]); },
246+
};
247+
248+
function renderLinkedCards(width = 390) {
249+
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: width });
250+
opened.length = 0;
251+
const onRowClick = vi.fn();
252+
const onRowSelect = vi.fn();
253+
const dataSource = {
254+
find: vi.fn(async () => ({ data: LINKED_ROWS, total: LINKED_ROWS.length, hasMore: false, pageSize: 50 })),
255+
getObjectSchema: async (name: string) => ({
256+
name,
257+
nameField: 'name',
258+
fields: {
259+
id: { type: 'text' },
260+
name: { type: 'text', label: 'Name' },
261+
email: { type: 'email', label: 'Email' },
262+
owner: { type: 'lookup', label: 'Owner', reference: 'sys_user' },
263+
},
264+
}),
265+
} as never;
266+
render(
267+
<ActionProvider>
268+
<RelatedRecordActionsProvider value={host}>
269+
<SchemaRendererProvider dataSource={dataSource}>
270+
<div data-testid="page-column">
271+
<ObjectGrid
272+
schema={{
273+
type: 'object-grid',
274+
objectName: 'account_36044',
275+
columns: [{ field: 'name' }, { field: 'email' }, { field: 'owner' }],
276+
selection: { type: 'multiple' },
277+
pagination: { pageSize: 50 },
278+
} as never}
279+
dataSource={dataSource}
280+
onRowClick={onRowClick}
281+
onRowSelect={onRowSelect}
282+
// An edit makes the card draw the row's 「⋮」 (objectstack#29150).
283+
onEdit={vi.fn()}
284+
/>
285+
</div>
286+
</SchemaRendererProvider>
287+
</RelatedRecordActionsProvider>
288+
</ActionProvider>,
289+
);
290+
return { onRowClick, onRowSelect };
291+
}
292+
293+
const mailOf = async (address: string) => {
294+
await waitFor(() => expect(document.querySelector(`a[href="mailto:${address}"]`)).not.toBeNull());
295+
return document.querySelector<HTMLElement>(`a[href="mailto:${address}"]`)!;
296+
};
297+
const chipOf = async (id: string) => {
298+
await waitFor(() => expect(document.querySelector(`a[href="/apps/demo/sys_user/record/${id}"]`)).not.toBeNull());
299+
return document.querySelector<HTMLElement>(`a[href="/apps/demo/sys_user/record/${id}"]`)!;
300+
};
301+
const startSelecting = async () => {
302+
act(() => requestListSelection(screen.getByTestId('page-column')));
303+
await waitFor(() => expect(screen.getAllByTestId('grid-card-check')).toHaveLength(2));
304+
};
305+
const endSelecting = () => {
306+
fireEvent.click(within(screen.getByTestId('bulk-actions-bar')).getByTestId('bulk-selection-clear'));
307+
expect(screen.queryAllByTestId('grid-card-check')).toHaveLength(0);
308+
};
309+
310+
it('a tap on the email ticks the card and opens nothing; after 「×」 the same tap opens the link', async () => {
311+
const { onRowClick, onRowSelect } = renderLinkedCards();
312+
await mailOf('ada@acme.test');
313+
await startSelecting();
314+
// `fireEvent` answers false when the click's default (following the
315+
// mailto) was cancelled.
316+
expect(fireEvent.click(await mailOf('ada@acme.test')), 'the link does not open').toBe(false);
317+
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
318+
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
319+
expect(fireEvent.click(await mailOf('hank@globex.test'))).toBe(false);
320+
expect(await cardOf('Globex')).toHaveAttribute('aria-pressed', 'true');
321+
// A second tap on the same link unticks its card.
322+
expect(fireEvent.click(await mailOf('hank@globex.test'))).toBe(false);
323+
expect(await cardOf('Globex')).toHaveAttribute('aria-pressed', 'false');
324+
expect(onRowClick).not.toHaveBeenCalled();
325+
326+
endSelecting();
327+
const ticks = onRowSelect.mock.calls.length;
328+
expect(fireEvent.click(await mailOf('ada@acme.test')), 'the link opens again').toBe(true);
329+
expect(onRowSelect).toHaveBeenCalledTimes(ticks);
330+
expect(screen.queryAllByTestId('grid-card-check')).toHaveLength(0);
331+
expect(onRowClick).not.toHaveBeenCalled();
332+
});
333+
334+
it('a tap on the referenced record\'s chip ticks the card and opens no record; after 「×」 it opens it', async () => {
335+
const { onRowClick, onRowSelect } = renderLinkedCards();
336+
await chipOf('u9');
337+
await startSelecting();
338+
expect(fireEvent.click(await chipOf('u9'))).toBe(false);
339+
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
340+
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
341+
expect(opened).toEqual([]);
342+
expect(onRowClick).not.toHaveBeenCalled();
343+
344+
endSelecting();
345+
fireEvent.click(await chipOf('u9'));
346+
expect(opened).toEqual([['sys_user', 'u9']]);
347+
});
348+
349+
it('a tap on the card\'s 「⋮」 ticks the card and opens no menu', async () => {
350+
const { onRowSelect } = renderLinkedCards();
351+
await mailOf('ada@acme.test');
352+
await startSelecting();
353+
await userEvent.click(within(await cardOf('Acme')).getByTestId('row-action-trigger'));
354+
expect(screen.queryByRole('menu')).toBeNull();
355+
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
356+
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
357+
});
358+
359+
it('a long press on the email starts the selection with its card ticked, and the click that ends it opens nothing', async () => {
360+
const { onRowClick, onRowSelect } = renderLinkedCards();
361+
const mail = await mailOf('ada@acme.test');
362+
fireEvent.pointerDown(mail, { clientX: 10, clientY: 10 });
363+
await hold(600);
364+
fireEvent.pointerUp(mail);
365+
expect(fireEvent.click(mail), 'the link does not open').toBe(false);
366+
expect(await cardOf('Acme')).toHaveAttribute('aria-pressed', 'true');
367+
expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]);
368+
expect(onRowClick).not.toHaveBeenCalled();
369+
});
370+
371+
it('on a desktop width the table keeps its links while rows are ticked', async () => {
372+
const { onRowSelect } = renderLinkedCards(1280);
373+
const mail = await mailOf('ada@acme.test');
374+
expect(document.querySelector('[data-testid="grid-mobile-card"]'), 'the table, not the cards').toBeNull();
375+
const row = mail.closest('tr') as HTMLElement;
376+
fireEvent.click(within(row).getByRole('checkbox'));
377+
await waitFor(() => expect(onRowSelect).toHaveBeenLastCalledWith([expect.objectContaining({ id: 'a1' })]));
378+
const ticks = onRowSelect.mock.calls.length;
379+
expect(fireEvent.click(await mailOf('ada@acme.test')), 'the link opens').toBe(true);
380+
fireEvent.click(await chipOf('u9'));
381+
expect(opened).toEqual([['sys_user', 'u9']]);
382+
expect(onRowSelect).toHaveBeenCalledTimes(ticks);
383+
});
384+
});
385+
224386
function SelectableProbe({ scope }: { scope: HTMLElement }) {
225387
return <span data-testid="selectable-probe" data-selectable={String(useListPageSelectable(scope))} />;
226388
}

0 commit comments

Comments
 (0)