From 16bd25b79af17e0f88f83788e5b035e7094dbc38 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 01:23:06 +0000 Subject: [PATCH 1/2] test(fields): pin a tap on a lookup option preview chip selecting the option (repro) Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD --- ...LookupField.previewLinkFree-36479.test.tsx | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx diff --git a/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx b/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx new file mode 100644 index 00000000000..e3b95fadb26 --- /dev/null +++ b/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx @@ -0,0 +1,148 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * A tap anywhere on a lookup quick-picker option selects that option — + * objectstack#36479. + * + * Seen on the showcase Field Zoo record at 375 px: editing the Master-Detail + * field (target: Project) and tapping the record chip `Account: Fabrikam` + * inside an option's preview opened the Fabrikam record mid-edit; the option + * was not selected. The preview draws each column through the read cell, and + * the read cell draws a reference as a link to its record whenever the host + * answers `recordHref`. The link's own click handler stops propagation and + * hands the click to the host's `openRecord`, so the option row never heard it + * — whatever the pointer: a mouse click on a desktop did the same. + * + * The rule is the picker table's (objectui#11903, point 7), now held by the + * one renderer both picker surfaces call (`renderLookupColumnValue`): a + * candidate's column never renders as a navigational link. A reference keeps + * its face (the record page's chip) without the anchor, and a type that draws + * its own anchor (`mailto:`, a URL, `tel:`, a file) is drawn with the text face. + */ + +import * as React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, cleanup, waitFor, act, fireEvent } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import '@testing-library/jest-dom'; +import { RelatedRecordActionsProvider } from '@object-ui/react'; +import { LookupField } from './LookupField'; +// Installs the cell-renderer resolver the preview draws its values with, and +// the record page's chip context. +import { ReferenceChipContext } from '../index'; + +/** The referenced object (`showcase_project`) as `getObjectSchema` serves it. */ +const FIELDS: Record> = { + name: { type: 'text', label: 'Project Name' }, + account: { type: 'lookup', label: 'Account', reference: 'showcase_account' }, + contact_email: { type: 'email', label: 'Contact Email' }, +}; + +const ROW = { + id: 'prj_1', + name: 'Website Relaunch', + // As the candidate query serves it, `$expand`-ed (objectui#10223). + account: { id: 'acc_9', name: 'Fabrikam' }, + contact_email: 'pm@fabrikam.example.com', +}; + +function makeDataSource() { + return { + find: vi.fn(async () => ({ data: [ROW], total: 1 })), + findOne: vi.fn(async () => ROW), + getObjectSchema: vi.fn(async (objectName: string) => ({ name: objectName, fields: FIELDS })), + }; +} + +/** The record page's host: it routes every object, and opens records in-app. */ +function makeHost() { + return { + recordHref: (objectName: string, recordId: string | number) => + `/apps/showcase/${objectName}/record/${encodeURIComponent(String(recordId))}`, + openRecord: vi.fn(), + }; +} + +async function openPicker(columns: string[]) { + const host = makeHost(); + const onChange = vi.fn(); + render( + // The record page's field area: references are drawn as chips (objectstack#36147). + + + ({ field, label: FIELDS[field].label as string })), + } as never} + /> + + , + ); + await act(async () => { + fireEvent.click(screen.getByTestId('lookup-trigger')); + }); + await waitFor(() => expect(screen.getByText('Website Relaunch')).toBeInTheDocument()); + return { host, onChange }; +} + +/** The value one previewed column renders. */ +function previewValue(field: string): HTMLElement { + const el = document.querySelector(`[data-lookup-preview="${field}"]`); + if (!el) throw new Error(`no previewed value for ${field}`); + return el; +} + +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); + +describe('LookupField option preview: a record chip selects its option (objectstack#36479)', () => { + // Touch (the phone the card was read on) and a mouse (a desktop) take the + // same path: the defect was the link's click handler, not the pointer. + it.each(['[TouchA]', '[MouseLeft]'])('%s on the chip selects the option and opens no record', async (keys) => { + const { host, onChange } = await openPicker(['account']); + const chip = await waitFor(() => { + const el = previewValue('account').querySelector('[data-record-chip]'); + if (!el) throw new Error('the account column drew no chip'); + return el; + }); + expect(chip).toHaveTextContent('Fabrikam'); + + // No anchor anywhere inside the option: an anchor is a second click + // target competing with the option's own select. + const option = screen.getByRole('option'); + expect(option.querySelector('a')).toBeNull(); + + const user = userEvent.setup(); + await user.pointer({ keys, target: chip }); + + expect(host.openRecord).not.toHaveBeenCalled(); + expect(onChange).toHaveBeenCalledTimes(1); + expect(onChange.mock.calls[0][0]).toBe('prj_1'); + }); + + it('draws a self-linking column with its text face, so a tap on it selects too', async () => { + const { onChange } = await openPicker(['contact_email']); + const value = previewValue('contact_email'); + await waitFor(() => expect(value).toHaveTextContent('pm@fabrikam.example.com')); + expect(screen.getByRole('option').querySelector('a')).toBeNull(); + + const user = userEvent.setup(); + await user.click(value); + + expect(onChange).toHaveBeenCalledTimes(1); + expect(onChange.mock.calls[0][0]).toBe('prj_1'); + }); +}); From 186d4b4246ec21f45537eb0f06d5cee97ec12bb6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 01:31:25 +0000 Subject: [PATCH 2/2] fix(fields): a candidate's column in a lookup picker never renders as a link The quick-picker's option preview drew a reference column through the read cell, which links the referenced record when the host answers recordHref; the link's click handler stopped propagation and opened the record, so a tap on a record chip in an option's preview navigated instead of selecting the option. renderLookupColumnValue, the one renderer both picker surfaces call, now draws every cell under a host with no record destination and draws self-linking types with the text face, the rule the dialog table already applied on its own. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01ADHkmNmMEXS4EzeVz9RjvD --- .changeset/36479-lookup-preview-link-free.md | 14 +++++ ...LookupField.previewLinkFree-36479.test.tsx | 23 +++++--- .../src/widgets/lookupColumnDisplay.tsx | 56 ++++++++++++++++++- 3 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 .changeset/36479-lookup-preview-link-free.md diff --git a/.changeset/36479-lookup-preview-link-free.md b/.changeset/36479-lookup-preview-link-free.md new file mode 100644 index 00000000000..1304cbe8de8 --- /dev/null +++ b/.changeset/36479-lookup-preview-link-free.md @@ -0,0 +1,14 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): a tap anywhere on a lookup picker option selects it, including on a record chip in its preview + +Clause-②: no +Metadata-protocol: none + +A lookup picker's option shows a preview of its other columns under its label. A column that references another record drew a link to that record there (on a record page, its chip), and a tap or a click on it opened that record instead of selecting the option, leaving the edit behind. An email, URL or phone column in the preview did the same with the mail client, the browser or the dialer. + +The preview now draws every column the way the "browse all records" picker table already did: a reference keeps its face, the record page's chip included, without the link, and an email, URL, phone or file column shows its text. A tap or a click anywhere on the option selects it, on a phone and on a desktop. Both picker surfaces now take this rule from the one renderer they share. + +What does not change: the read cells outside the picker (record page fields, list and grid cells) keep their links. No metadata key, value or default changes. diff --git a/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx b/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx index e3b95fadb26..dff4c3b5b54 100644 --- a/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx +++ b/ui/packages/fields/src/widgets/LookupField.previewLinkFree-36479.test.tsx @@ -28,7 +28,7 @@ import * as React from 'react'; import { describe, it, expect, vi, afterEach } from 'vitest'; -import { render, screen, cleanup, waitFor, act, fireEvent } from '@testing-library/react'; +import { render, screen, cleanup, waitFor, act, fireEvent, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import { RelatedRecordActionsProvider } from '@object-ui/react'; @@ -120,11 +120,6 @@ describe('LookupField option preview: a record chip selects its option (objectst }); expect(chip).toHaveTextContent('Fabrikam'); - // No anchor anywhere inside the option: an anchor is a second click - // target competing with the option's own select. - const option = screen.getByRole('option'); - expect(option.querySelector('a')).toBeNull(); - const user = userEvent.setup(); await user.pointer({ keys, target: chip }); @@ -133,16 +128,28 @@ describe('LookupField option preview: a record chip selects its option (objectst expect(onChange.mock.calls[0][0]).toBe('prj_1'); }); + it('draws the chip with no anchor, so the option is the one click target', async () => { + await openPicker(['account']); + await waitFor(() => + expect(previewValue('account').querySelector('[data-record-chip]')).toHaveTextContent('Fabrikam'), + ); + expect(screen.getByRole('option').querySelector('a')).toBeNull(); + }); + it('draws a self-linking column with its text face, so a tap on it selects too', async () => { const { onChange } = await openPicker(['contact_email']); const value = previewValue('contact_email'); await waitFor(() => expect(value).toHaveTextContent('pm@fabrikam.example.com')); - expect(screen.getByRole('option').querySelector('a')).toBeNull(); + + // Read before the pick: a pick closes the popover. + const anchor = screen.getByRole('option').querySelector('a'); const user = userEvent.setup(); - await user.click(value); + // The element that carries the address's text: the anchor, before the fix. + await user.click(within(value).getByText('pm@fabrikam.example.com')); expect(onChange).toHaveBeenCalledTimes(1); expect(onChange.mock.calls[0][0]).toBe('prj_1'); + expect(anchor).toBeNull(); }); }); diff --git a/ui/packages/fields/src/widgets/lookupColumnDisplay.tsx b/ui/packages/fields/src/widgets/lookupColumnDisplay.tsx index 383d0ae2267..f2aef5ef105 100644 --- a/ui/packages/fields/src/widgets/lookupColumnDisplay.tsx +++ b/ui/packages/fields/src/widgets/lookupColumnDisplay.tsx @@ -37,6 +37,7 @@ import React from 'react'; import { formatDate, getRecordDisplayName } from '@object-ui/core'; +import { RelatedRecordActionsProvider, useRelatedRecordActions } from '@object-ui/react'; import type { LookupColumnDef } from '@object-ui/types'; import { BooleanValueText } from './booleanValueLabel.js'; @@ -167,9 +168,54 @@ export interface LookupColumnRenderContext { displayLocale?: string; } +/** + * Cell renderer keys that draw their value as their OWN anchor without asking + * the host — `mailto:`, a URL, `tel:`, and the file family's download link. A + * candidate's column draws them with {@link PICKER_TEXT_FACE} instead: the + * address, the URL, the number, the file's name. + */ +const PICKER_SELF_LINKING_CELL_TYPES: ReadonlySet = new Set([ + 'email', + 'url', + 'phone', + 'file', + 'video', + 'audio', +]); + +/** The cell renderer key a self-linking value is drawn with in a picker. */ +const PICKER_TEXT_FACE = 'text'; + +/** + * The reference family (the lookup cell's `ReferencedRecordLink`, its hover + * card) draws an anchor only when the host answers `recordHref`; under this + * wrapper the host answers no record destination, which the context documents + * as "render the plain value". Every other member of the host passes through; + * with no host there is nothing to withhold. + */ +function WithoutRecordLinks({ children }: { children: React.ReactNode }): React.ReactElement { + const host = useRelatedRecordActions(); + if (!host) return <>{children}; + return ( + + {children} + + ); +} + /** * Render one column of one candidate record. * + * A candidate's column is never a navigational link, on either picker surface: + * the option row (the dropdown) or the table row (the browse-all dialog) is the + * one click target, and a link inside it is a second one that competes with + * the pick — a record chip opening its record, a `mailto:` opening the mail + * client, instead of selecting the candidate (objectui#11903, + * objectstack#36479). So a self-linking type is drawn with the text face + * ({@link PICKER_SELF_LINKING_CELL_TYPES}), and every cell renders under a host + * with no record destination ({@link WithoutRecordLinks}): a reference keeps + * its face — the record page's chip included — without the anchor. + * * Order: * 1. the record title, for the display column only and only when the * referenced object's schema is given: `getRecordDisplayName` with the @@ -213,9 +259,15 @@ export function renderLookupColumnValue( // schema field's type via `fieldsMeta`) and a resolver are available. const descriptor = descriptors[col.field]; if (descriptor && cellRenderer) { - const Renderer = cellRenderer(descriptor.type); + const Renderer = cellRenderer( + PICKER_SELF_LINKING_CELL_TYPES.has(descriptor.type) ? PICKER_TEXT_FACE : descriptor.type, + ); if (Renderer) { - return ; + return ( + + + + ); } }