Skip to content

Commit dc10b3b

Browse files
fix(grid): in a list cell a single click only selects; no copy buttons (#36015) (#36033)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu2yMB8uuX9RDZCxYnGyuHiY)_ repo:objectstack#1 · os-sales · session_01L6bhgTQn1haiL13TBfwmxm Refs #36015 The card's scope changed after this PR was opened (maintainer, 2026-11-21 11:13Z: lookup chips open the referenced record in the side drawer on a single click, with a pencil button on lookup cells). This PR lands everything the revision kept. The lookup-cell part follows in its own PR, which carries `Fixes #36015`. Until then, a lookup chip selects its cell on a single click and opens with Ctrl/Cmd-click, the open button or Ctrl/Cmd+Enter. Clause-②: no Metadata-protocol: none ## 维护者速读 - 列表格子里单击只做一件事:选中这一格。点邮箱、电话、网址、文件、关联记录或人员的小标签、图片缩略图,都只是选中,不再打开邮件程序、拨号、网页或跳到别的记录。 - 想打开时有三条路:按住 Ctrl / Cmd 再点;选中这一格后鼠标移上去,格子右边出现「打开」小图标,点它;或选中后按 Ctrl+Enter / Cmd+Enter。一格里有多个标签时,图标和快捷键打开第一个。 - 邮箱、电话格里的复制按钮在列表里不再出现;复制用选中后 Ctrl+C / Cmd+C。双击邮箱文字照常进入编辑。 - 名称列不变:单击名称进记录页。记录页、相关列表、手机卡片、看板卡片都不变(它们没有「先选中」的格子模型)。 - 风险:改了 data-table、字段格子渲染和名称列链接三处;没有新导出、没有新文案键(「打开」复用已有的 `table.open`)。 ## What changes The rule, on a grid with the select-first cell model (`GridCellSelectionProvider`, mounted by `ObjectGrid` when its host passes `cellSelection`; today the console's list page): **a single click on a cell only selects it.** **`@object-ui/components`: `dataTableCellSelection.ts`, `data-table.tsx`** - New `cellOpenerAt` / `firstCellOpener`: a cell's *opener* is any `a[href]` it draws, except one marked `data-opens-on-click`, plus any element marked `data-cell-opener`. - `isCellWidgetTarget` no longer counts an opener as a widget. A press on a link is a press on the cell, so a double-click on the email text edits, and the double-click's word selection is suppressed as on any cell. - Each select-first cell gets an `onClickCapture`. A plain primary click on an opener calls `preventDefault` (no `mailto:`, `tel:`, new tab or download), stops the event before the opener's own handler (no SPA navigation), and selects the cell. A Ctrl, Cmd, Shift or Alt click, a non-primary button, a touch tap and a click inside an open editor pass through unchanged. - The selected cell draws `CellOpenButton`, an icon button at its right edge labelled with the existing `table.open` key. It is shown on cell hover (`group-hover/cell`) and drawn only while the cell holds an opener; a `MutationObserver` catches a lookup chip that becomes a link after its name is read. It takes no focus (`tabIndex=-1`, `mousedown` prevented), so typing carries on in the cell. It never appears on an unselected cell or on row hover. - Ctrl/Cmd+Enter on the selected cell (the type catcher) opens the cell's first opener; with no opener the key does nothing. Plain Enter still edits. - Opening means clicking the opener for the reader (`openCellOpener`) while a ref tells the capture handler to let it through. Each value keeps its own behaviour: the host's `openRecord` for a referenced record, the browser's for `mailto:` / `tel:` / `target=_blank`, the lightbox for an image. - Select-first cells carry `[&_[data-cell-copy]]:hidden`, so a copy control a value draws is not drawn there. Ctrl/Cmd+C on the selected cell copies, as before. **`@object-ui/fields`: `index.tsx`** - The email and phone copy buttons carry `data-cell-copy`. These are the only copy buttons a cell renderer draws (searched `clipboard.writeText` and the `Copy` icon across `fields`, `plugin-grid`, `components` renderers and `react`; the other hits are edit widgets or grid-level hooks). - Image thumbnails (single, stacked, and the `+N` button) carry `data-cell-opener`. **`@object-ui/plugin-grid`: `objectGridLinkCell.tsx`** - The name column's record link (`RecordLink` anchor) carries `data-opens-on-click`. It is the one link a single click still follows (card item 5). Its span fallback (no host URL) is `role="link"`, which stays a widget and keeps its click. **Field types this reaches in a list cell:** email, phone, url, file / video / audio (download link), image (thumbnail lightbox), restricted file (lock link), lookup / master_detail / tree and every other reference family drawn through `ReferencedRecordLink` (owner and other user lookups included), and any custom cell renderer that draws an `a[href]`. **Not changed (claim readings A–C):** - **A.** Only grids with the select-first model. Related lists, the record page's fields, phone cards (`ObjectGrid` below 768px), kanban cards, and every grid whose host does not pass `cellSelection` keep their links and copy buttons byte for byte. The copy buttons are hidden by the table, not removed by the renderer, for exactly this reason: the phone card under the same provider still draws them. - **B.** A cell of several chips opens the first one by the button or Ctrl/Cmd+Enter; a Ctrl/Cmd-click opens the one clicked. - **C.** File links and image thumbnails follow the same rule. Docs: `content/docs/frontend/plugins/plugin-grid.mdx` § On an object's list page (the click bullet and the selected-cell keys). ## Tests Rewritten, because it pinned the behaviour this card reverses: - `components/src/__tests__/data-table-select-first-35684.test.tsx`: the describe "a link in a cell keeps its click" ("a click on the link follows it and selects nothing; a double-click beside it edits") is replaced by "a click on a link the cell draws only selects (objectstack#36015)". It pins: a plain click selects and cancels the default, Ctrl/Cmd-click follows, a double-click on the link edits, the `data-opens-on-click` title link keeps its click (control), the open button appears only on the selected cell and follows the link, a cell with nothing to open hides the button, Ctrl/Cmd+Enter follows the link while plain Enter edits, and the copy-hiding class is present only under the provider (control without it). The fixture's link cell gained a `data-cell-copy` button; an opt-in `withTitle` column carries the title link. Added: - `plugin-grid/src/__tests__/ObjectGrid.cellSelection-35684.test.tsx`, new describe, end to end through `ObjectGrid` with a host that routes records: a click on the `mailto:` link and on the lookup chip selects each cell, cancels the default and opens nothing; Ctrl+Enter and the open button call the host's `openRecord` for the referenced record; the title link is the only `data-opens-on-click` element and keeps its click; the email cell draws its copy button marked `data-cell-copy` inside a cell that hides it. Unchanged and still green: `ObjectGrid.linkCellNoNestedAnchor-11817.test.tsx` ("an email column that is not the link column keeps its mailto anchor and copy button", a grid without `cellSelection`, the control for reading A), `cellRenderers.objectLiteral-8596.test.tsx`, `data-table-keys-35687`, `data-table-cell-overlay-35688`, `data-table-autosave-35685`. Local runs (`@objectstack/*` built with `OS_SKIP_DTS=1`; first on `be91bfc2`, the data-table / ObjectGrid / fields files again after merging `c00be39b`, which carries #36018 and #36021): - `vitest run packages/components/ packages/fields/ packages/plugin-grid/`: 1103 files passed. The only failing file is `share-filter-sort-spec-parity.test.ts`, which reads `@objectstack/spec`'s `.d.ts` that a DTS-less build does not write. - `vitest run packages/plugin-list/`: 180 files passed. The only failing file is `spec-symbol-batch6.test.tsx`, for the same reason. - After the merge: `vitest run packages/components/src/__tests__/` plus `ObjectGrid.cellSelection-35684`, `ObjectGrid.linkCellNoNestedAnchor-11817`, `selectionBar-35678` and `inCellFaces-35688`: 289 files passed; the same parity file failed, and `object-icon-tile-35985` failed against a stale spec build and passed once the spec was rebuilt. - `eslint` on the changed files: 0 errors. - `overlap-check` on the pushed head: clean against `origin/main`, no open PR shares a file. ## Verification (browser) CRM example (`--fresh`), Console via Vite HMR on this tree, Chromium. The before run used `origin/main`'s versions of the four source files. Screenshots and journey logs: project folder `build-seat1/36015/` (`before-*`, `after-*`). | Step (Contacts list, 1280) | Before | After | |:--|:--|:--| | Hover a row | copy icon beside each email | no copy icon | | Click the email text | `mailto:` request, cell not selected | cell selected, navigation cancelled | | Click the Account chip | page leaves for the account record | cell selected, page stays | | Selected chip cell, hover | no open button | open button at the right edge | | Ctrl+Enter on it | nothing | opens the account record | | Click the name | opens the contact record | same | | Double-click the email text | `mailto:` twice, no editor | editor opens | | Accounts list, click the Website link | new tab opened | cell selected, no tab | | 375 phone list | cards | same cards | ## Acceptance notes 1. Hover a row: no copy icon in the email or phone cell: yes (browser, email; phone shares the same marker and class, unit-pinned through the fixture). 2. Click the email text: the cell is selected, no mail program; Ctrl/Cmd+C copies the address: yes (Ctrl+C path unchanged, `String(row[col])`). 3. Phone and URL cells: same: yes (URL in the browser; phone is an `a[href^="tel:"]`, the same opener rule). 4. Owner chip and lookup chip: selected, the page does not leave: yes (the Account lookup chip in the browser; an owner or other user lookup draws the same `ReferencedRecordLink` anchor, not checked in the browser separately). 5. Ctrl/Cmd-click email opens the mail program; Ctrl/Cmd-click a chip opens the record: yes (the click passes through untouched). 6. The open icon appears on the selected lookup cell, opens the record, and is absent when the cell is not selected: yes. 7. Ctrl/Cmd+Enter opens: yes. 8. Click the name opens the record page as before: yes. 9. Double-click the email cell edits: yes. 10. Record page email and phone fields unchanged: yes (no select-first model there; renderer markup only gains attributes). 11. This body lists the field types reached and the rewritten tests: above. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgTQn1haiL13TBfwmxm)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgTQn1haiL13TBfwmxm <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgTQn1haiL13TBfwmxm --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent cda16d4 commit dc10b3b

8 files changed

Lines changed: 345 additions & 22 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/fields': patch
4+
'@object-ui/plugin-grid': patch
5+
---
6+
7+
fix(grid): in a list cell a single click only selects, and the email and phone cells draw no copy button
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
On a grid with the select-first cell model (the console's list page), a plain click on a link a cell draws used to follow it: an email opened the mail program, a phone number the dialler, a URL a new tab, a lookup or user chip that record's page, and an image thumbnail its lightbox. The cell was not selected, so a reader who meant to select or edit the cell left the list instead. The email and phone cells also drew a copy button beside the value, easy to hit while selecting.
13+
14+
A plain click on any of these now selects the cell and opens nothing. To open one: Ctrl/Cmd-click it (as before), press the open button the selected cell shows on hover (only on the selected cell, never on the row hover), or press Ctrl/Cmd+Enter on the selected cell. A cell of several chips opens the first one that way. A double-click on the link edits the cell, as on any other cell. The name link is the one exception and opens the record on a single click, as before. The copy buttons are not drawn inside such a grid; Ctrl/Cmd+C copies the selected cell.
15+
16+
Outside the select-first model nothing changes: the record page, related lists, phone cards, kanban cards and every grid whose host does not turn on `cellSelection` keep their links and copy buttons.
17+
18+
For renderer authors: a link (`a[href]`) inside a select-first cell is now treated as part of the cell's value. Mark the one link a single click must still follow with `data-opens-on-click`, a non-link control that opens what the value points at with `data-cell-opener`, and a copy control the grid should not draw with `data-cell-copy`.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,14 @@ object and the view does not declare `userActions.editInline: false`, and
397397
`singleClickEdit` is not read there.
398398

399399
- **A click selects** a cell (a ring around it); it neither edits nor opens the
400-
record. A link a cell draws (the name, a lookup, a phone or an email) keeps
401-
its own click. On a touch screen a tap opens the record.
400+
record. Only the name link keeps its own click (it opens the record). Every
401+
other link a cell draws (an email, a phone number, a URL, a file, a lookup or
402+
user chip, an image thumbnail) is selected by a click too (objectstack#36015);
403+
to open it, Ctrl/Cmd-click it, press the **Open** button the selected cell
404+
shows on hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the
405+
first one that way. The email and phone cells draw no copy button here:
406+
Ctrl/Cmd+C copies the selected cell. On a touch screen a tap opens the
407+
record.
402408
- **A cut-off value shows in full** when its cell is selected: a long text, a
403409
multi-line text or a list of tags that the column truncates opens on a
404410
layer over the cell, wrapped, scrolling inside past a few lines. Escape, an
@@ -425,8 +431,9 @@ object and the view does not declare `userActions.editInline: false`, and
425431
- **Selected cell keys:** the arrows and Tab move the selection; Space is typed
426432
like any other key and opens the editor (a checkbox cell flips instead, as
427433
do Enter and a second click on it); Ctrl/Cmd+C copies; Ctrl/Cmd+V converts the text
428-
to the field's type and commits it; Escape clears the selection. The record
429-
opens from the name link, or a tap on a touch screen.
434+
to the field's type and commits it; Ctrl/Cmd+Enter opens the link the cell
435+
draws; Escape clears the selection. The record opens from the name link, or
436+
a tap on a touch screen.
430437
- **A cell that opens no editor says why** on the cell: the field is read-only,
431438
calculated or not editable in a list, the reader may not edit the field, the
432439
object or the record, the view turned editing off, or the record is locked

‎ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx‎

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
* 3. Space is typed like any key and opens the editor, never the record
1919
* (the maintainer's correction on #35683); a two-state cell flips on
2020
* Space or on a second click instead, and commits.
21-
* 4. A link the cell draws keeps its own click; a double-click on the cell
22-
* around it edits.
21+
* 4. A plain click on a link the cell draws selects the cell and follows
22+
* nothing; a Ctrl/Cmd-click follows it, and a double-click on it edits
23+
* (objectstack#36015). The title link (`data-opens-on-click`) keeps its
24+
* click. The selected cell's open button and Ctrl/Cmd+Enter open the
25+
* link; a copy button a value draws is not drawn.
2326
* 5. A cell that opens no editor says why on the cell: the host's sentence,
2427
* else the table's own.
2528
* 6. A touch tap opens the record and edits nothing.
@@ -48,11 +51,23 @@ const ROWS = [
4851
function renderTable({
4952
selection = {},
5053
extra = {},
51-
}: { selection?: GridCellSelection | null; extra?: Record<string, unknown> } = {}) {
54+
withTitle = false,
55+
}: { selection?: GridCellSelection | null; extra?: Record<string, unknown>; withTitle?: boolean } = {}) {
5256
const DataTable = ComponentRegistry.get('data-table')!;
5357
const onRowClick = vi.fn();
5458
const onCellChange = vi.fn();
5559
const onSiteClick = vi.fn();
60+
const onTitleClick = vi.fn();
61+
// The title link a host marks as the one a click follows (objectstack#36015).
62+
const titleColumn = {
63+
header: 'Title',
64+
accessorKey: 'title',
65+
cell: (_value: unknown, row: { id: string }) => (
66+
<a href={`/record/${row.id}`} data-opens-on-click="" onClick={(e) => { e.preventDefault(); onTitleClick(row.id); }}>
67+
Record {row.id}
68+
</a>
69+
),
70+
};
5671
const schema = {
5772
type: 'data-table',
5873
columns: [
@@ -63,9 +78,13 @@ function renderTable({
6378
header: 'Site',
6479
accessorKey: 'site',
6580
cell: (value: string) => (
66-
<a href={`https://${value}`} onClick={(e) => { e.preventDefault(); onSiteClick(value); }}>{value}</a>
81+
<span>
82+
<a href={`https://${value}`} onClick={(e) => { e.preventDefault(); onSiteClick(value); }}>{value}</a>
83+
<button type="button" data-cell-copy="">Copy site</button>
84+
</span>
6785
),
6886
},
87+
...(withTitle ? [titleColumn] : []),
6988
],
7089
data: ROWS,
7190
editable: true,
@@ -85,7 +104,7 @@ function renderTable({
85104
utils.container.querySelectorAll('tbody tr')[row].querySelectorAll('td[data-grid-cell]')[col] as HTMLElement;
86105
const editor = () => utils.container.querySelector<HTMLInputElement>('td[data-editing-cell] input');
87106
const catcher = () => utils.container.querySelector<HTMLInputElement>('[data-slot="cell-type-catcher"]');
88-
return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick };
107+
return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick, onTitleClick };
89108
}
90109

91110
describe('data-table select-first — a click selects (objectstack#35684)', () => {
@@ -186,20 +205,78 @@ describe('data-table select-first — Space types; a two-state cell flips', () =
186205
});
187206
});
188207

189-
describe('data-table select-first — a link in a cell keeps its click', () => {
190-
it('a click on the link follows it and selects nothing; a double-click beside it edits', () => {
208+
describe('data-table select-first — a click on a link the cell draws only selects (objectstack#36015)', () => {
209+
it('a plain click selects the cell and follows nothing; a Ctrl or Cmd click follows the link', () => {
210+
const t = renderTable();
211+
const link = screen.getByText('a.example');
212+
const plain = fireEvent.click(link);
213+
expect(t.onSiteClick).not.toHaveBeenCalled();
214+
// The browser's own navigation was cancelled too.
215+
expect(plain).toBe(false);
216+
expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell');
217+
expect(t.onRowClick).not.toHaveBeenCalled();
218+
expect(document.activeElement).toBe(t.catcher());
219+
fireEvent.click(link, { ctrlKey: true });
220+
expect(t.onSiteClick).toHaveBeenCalledTimes(1);
221+
fireEvent.click(link, { metaKey: true });
222+
expect(t.onSiteClick).toHaveBeenCalledTimes(2);
223+
});
224+
225+
it('a double-click on the link edits, as on any cell', () => {
191226
const t = renderTable();
192227
fireEvent.click(screen.getByText('a.example'));
193-
expect(t.onSiteClick).toHaveBeenCalledWith('a.example');
194-
expect(t.cell(0, 3)).not.toHaveAttribute('data-selected-cell');
195228
fireEvent.doubleClick(screen.getByText('a.example'));
196-
expect(t.editor()).toBeNull();
197-
// The cell around the link.
229+
expect(t.editor()).toHaveValue('a.example');
230+
expect(t.onSiteClick).not.toHaveBeenCalled();
231+
});
232+
233+
it('control: the title link (data-opens-on-click) keeps its click and selects nothing', () => {
234+
const t = renderTable({ withTitle: true });
235+
fireEvent.click(screen.getByText('Record 1'));
236+
expect(t.onTitleClick).toHaveBeenCalledWith('1');
237+
expect(t.cell(0, 4)).not.toHaveAttribute('data-selected-cell');
238+
});
239+
240+
it('the selected cell draws an open button that follows the link; an unselected cell draws none', () => {
241+
const t = renderTable();
242+
expect(t.cell(0, 3).querySelector('[data-testid="cell-open-button"]')).toBeNull();
198243
fireEvent.click(t.cell(0, 3));
244+
const open = t.cell(0, 3).querySelector<HTMLButtonElement>('[data-testid="cell-open-button"]')!;
245+
expect(open).toHaveAccessibleName('Open');
246+
expect(open.className).toContain('flex');
247+
fireEvent.click(open);
248+
expect(t.onSiteClick).toHaveBeenCalledWith('a.example');
249+
// The cell stays selected.
199250
expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell');
200-
fireEvent.doubleClick(t.cell(0, 3));
251+
});
252+
253+
it('a selected cell with nothing to open hides its open button', () => {
254+
const t = renderTable();
255+
fireEvent.click(t.cell(0, 0));
256+
const open = t.cell(0, 0).querySelector<HTMLButtonElement>('[data-testid="cell-open-button"]')!;
257+
expect(open.className).toContain('hidden');
258+
expect(open.className).not.toMatch(/(^|\s)flex(\s|$)/);
259+
});
260+
261+
it('Ctrl or Cmd+Enter on the selected cell follows the link; plain Enter edits', () => {
262+
const t = renderTable();
263+
fireEvent.click(t.cell(0, 3));
264+
fireEvent.keyDown(t.catcher()!, { key: 'Enter', ctrlKey: true });
265+
expect(t.onSiteClick).toHaveBeenCalledTimes(1);
266+
fireEvent.keyDown(t.catcher()!, { key: 'Enter', metaKey: true });
267+
expect(t.onSiteClick).toHaveBeenCalledTimes(2);
268+
expect(t.editor()).toBeNull();
269+
fireEvent.keyDown(t.catcher()!, { key: 'Enter' });
201270
expect(t.editor()).toHaveValue('a.example');
202271
});
272+
273+
it('a copy button a value draws is hidden in the select-first table, and only there', () => {
274+
const t = renderTable();
275+
expect(t.cell(0, 3).className).toContain('[&_[data-cell-copy]]:hidden');
276+
cleanup();
277+
const control = renderTable({ selection: null, extra: { keyboardNavigation: true } });
278+
expect(control.cell(0, 3).className).not.toContain('[data-cell-copy]');
279+
});
203280
});
204281

205282
describe('data-table select-first — a cell that opens no editor says why', () => {

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DisabledReasonMenuLabel, menuItemReasonAria, useDisabledReason } from '
1515
import { useGridFieldAuthoring } from '../../context/gridFieldAuthoring';
1616
import { useGridCellSelection } from '../../context/gridCellSelection';
1717
import { useGridHeaderMenu } from '../../context/gridHeaderMenu';
18-
import { caretToEnd, defaultTyping, defaultValueFromText, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection';
18+
import { caretToEnd, cellOpenerAt, defaultTyping, defaultValueFromText, firstCellOpener, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection';
1919
import { useHorizontalOverflow, HOVER_SCROLLBAR_CLASSES } from '../../custom/use-horizontal-overflow';
2020
import { ActiveListRow, listRecordIdOf } from '../../custom/record-list-face';
2121
import { describeIgnoredBind, describeNonArrayData } from './dataTableBindDiagnostic';
@@ -69,6 +69,7 @@ import {
6969
AlertCircle,
7070
Check,
7171
Loader2,
72+
SquareArrowOutUpRight,
7273
} from 'lucide-react';
7374
import {
7475
DropdownMenu,
@@ -1418,6 +1419,53 @@ function CellNotice({ text, onDismiss }: { text: string; onDismiss: () => void }
14181419
);
14191420
}
14201421

1422+
/**
1423+
* objectstack#36015 — the selected cell's "open" button: drawn only while the
1424+
* cell draws something that opens (a link, a referenced record's chip, an
1425+
* image), shown when the pointer is over the cell. A plain click on that
1426+
* thing only selected the cell; this opens it. It takes no focus, so typing
1427+
* carries on in the cell, and the keyboard's way is Ctrl/Cmd+Enter.
1428+
*/
1429+
function CellOpenButton({ label, onOpen }: { label: string; onOpen: (cell: HTMLElement) => void }) {
1430+
const ref = useRef<HTMLButtonElement>(null);
1431+
const [cell, setCell] = useState<HTMLElement | null>(null);
1432+
const [opens, setOpens] = useState(false);
1433+
useLayoutEffect(() => {
1434+
const host = ref.current?.closest<HTMLElement>('td') ?? null;
1435+
setCell(host);
1436+
if (!host) return undefined;
1437+
// A referenced record's name is read after the cell first draws, and its
1438+
// chip becomes a link only then.
1439+
const measure = () => setOpens(firstCellOpener(host) !== null);
1440+
measure();
1441+
if (typeof MutationObserver === 'undefined') return undefined;
1442+
const observer = new MutationObserver(measure);
1443+
observer.observe(host, { childList: true, subtree: true, attributes: true, attributeFilter: ['href'] });
1444+
return () => observer.disconnect();
1445+
}, []);
1446+
return (
1447+
<button
1448+
ref={ref}
1449+
type="button"
1450+
tabIndex={-1}
1451+
aria-label={label}
1452+
title={label}
1453+
data-testid="cell-open-button"
1454+
className={cn(
1455+
'absolute right-1 top-1/2 z-20 size-5 -translate-y-1/2 items-center justify-center rounded border bg-background text-muted-foreground opacity-0 shadow-sm transition-opacity hover:text-foreground group-hover/cell:opacity-100',
1456+
opens ? 'flex' : 'hidden',
1457+
)}
1458+
onMouseDown={(e) => e.preventDefault()}
1459+
onClick={(e) => {
1460+
e.stopPropagation();
1461+
if (cell) onOpen(cell);
1462+
}}
1463+
>
1464+
<SquareArrowOutUpRight className="size-3" aria-hidden="true" />
1465+
</button>
1466+
);
1467+
}
1468+
14211469
/**
14221470
* objectstack#35685 — why a list cell's save was refused, said on that cell:
14231471
* the server's reasons, one line each, and, when the refusal names a field the
@@ -3638,6 +3686,22 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
36383686

36393687
const factsOf = (row: any, col: TableColumn) => cellSelection?.describeCell?.(row, col.accessorKey) ?? null;
36403688

3689+
// objectstack#36015 — while set, a click on a cell's opener follows it: the
3690+
// open button or Ctrl/Cmd+Enter is clicking it on the reader's behalf.
3691+
const followingOpenerRef = useRef(false);
3692+
/** Opens what the cell draws (its first opener); `false` when it draws none. */
3693+
const openCellOpener = (cell: Element): boolean => {
3694+
const opener = firstCellOpener(cell);
3695+
if (!opener) return false;
3696+
followingOpenerRef.current = true;
3697+
try {
3698+
opener.click();
3699+
} finally {
3700+
followingOpenerRef.current = false;
3701+
}
3702+
return true;
3703+
};
3704+
36413705
/**
36423706
* objectstack#36023 — why the open editor's value may not be committed, or
36433707
* `null`: first what the browser itself cannot read in the editor's input (a
@@ -3817,6 +3881,11 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
38173881
return;
38183882
}
38193883
setCellNotice(null);
3884+
if (onCatcher && e.key === 'Enter' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
3885+
// objectstack#36015 — Ctrl/Cmd+Enter opens what the selected cell draws.
3886+
if (openCellOpener(e.currentTarget)) e.preventDefault();
3887+
return;
3888+
}
38203889
const next = navigationTarget(e, rowIndex, colIndex);
38213890
if (next) {
38223891
e.preventDefault();
@@ -5044,6 +5113,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
50445113
// reader deselected with Esc keeps the focus with no ring.
50455114
selectFirst && "outline-none",
50465115
selectFirst && !isFrozen && "relative",
5116+
// objectstack#36015 — a single click selects, and Ctrl/Cmd+C copies
5117+
// the selected cell, so the copy buttons a value draws are not drawn.
5118+
selectFirst && "group/cell [&_[data-cell-copy]]:hidden",
50475119
!autosaves && hasPendingChange && "font-semibold text-amber-700 dark:text-amber-400",
50485120
cellError !== undefined && "ring-2 ring-inset ring-destructive",
50495121
isFrozen && ['sticky z-10 bg-background', STICKY_ROW_TINT],
@@ -5066,6 +5138,17 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
50665138
// where its column does.
50675139
...(pinnedRightOffset ? { right: pinnedRightOffset } : {}),
50685140
}}
5141+
onClickCapture={selectFirst ? (e) => {
5142+
// objectstack#36015 — a plain click on a link, a referenced
5143+
// record's chip or an image the cell draws selects the cell and
5144+
// opens nothing. A modifier click opens it as it always did.
5145+
if (isEditing || followingOpenerRef.current || isTouchPress(e)) return;
5146+
if (cellOpenerAt(e.target, e.currentTarget) === null) return;
5147+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
5148+
e.preventDefault();
5149+
e.stopPropagation();
5150+
selectCell(rowIndex, colIndex);
5151+
} : undefined}
50695152
onMouseDown={selectFirst ? (e) => {
50705153
// The double-click is the edit gesture here, so its second
50715154
// press does not select the word under the pointer.
@@ -5195,6 +5278,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
51955278
}}
51965279
/>
51975280
)}
5281+
{isSelectedCell && !isEditing && (
5282+
<CellOpenButton label={t('table.open')} onOpen={openCellOpener} />
5283+
)}
51985284
{cellNotice?.rowIndex === rowIndex && cellNotice.colIndex === colIndex && (
51995285
<CellNotice text={cellNotice.text} onDismiss={() => setCellNotice(null)} />
52005286
)}

0 commit comments

Comments
 (0)