Skip to content

Commit 8aed508

Browse files
fix(fields): an Enter that picks an input-method candidate no longer moves the grid field, commits a date or jumps the picker page; one isImeKey (#36126)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuVwX4pUdM1qvNLSqRZNSvv3)_ Fixes #35996 Clause-②: yes (widening): the `@object-ui/components` entry gains one value export, `isImeKey(e: { nativeEvent: KeyboardEvent; keyCode?: number }): boolean`. Measured on the built declarations: the components `dist/index.d.ts` gains exactly `export { isImeKey } from './lib/ime-key.js';` plus the new `lib/ime-key.d.ts`. The `@object-ui/fields` entry declarations are byte-identical to main (`index.d.ts` unchanged; 120 of 121 emitted `.d.ts` identical, and the one that differs is the internal `widgets/imeKey.d.ts`, which no export path and no other `.d.ts` reaches). Nothing is removed or narrowed. Metadata-protocol: none Skills-docs: none — no skill teaches the input-method key guard (zero hits for `isImeKey` or `isComposing` under `skills/`), and field behaviour outside a composition is unchanged repo:objectstack#1 · os-sales · session_01L6bhgW85kwjGaz7HqsmEuv ## 维护者速读 - 用中文、日文、韩文输入法打字时,按回车选词不再误触发:表单里的明细表格不再跳到下一行或多加一行,日期框不再把打了一半的日期当成输入提交,选择记录弹窗的页码框不再跳页、清空。 - 这是输入法回车问题的收尾,前一张卡修了标签、查找、人员三个控件,这次补上剩下三个,并把判断「这个键归输入法」的规则合成一份,以后改一处就全生效。 - 出错的话最多是这三处在输入法下按回车没反应;不碰数据和保存逻辑,可以直接撤回。 - 要你做什么:无。 ## What changes **Three guards** (`@object-ui/fields`), each the first line of the handler: - `GridField` cell `onKeyDown` (`onCellKeyDown`): a key the input method owns no longer moves to the next line or appends one on the last line. The same guard covers this handler's ArrowUp and ArrowDown, which an input method uses to move through its candidates. The guard sits on line 1 of `onCellKeyDown`, which open PR #36039 (S5) leaves unchanged, so it applies the same way to S5's extra callers of the handler. - `DatePickerField` / `DateTimePickerField`: the candidate-picking Enter no longer commits the half-typed text. Since #36054 (S4) both the field face and the in-cell panel draw the text box through one `textBox` helper, so the guard is on that single Enter handler and covers both. - `RecordPickerDialog` page-jump box (`handlePageJump`): the candidate-picking Enter no longer jumps or clears the box. **One predicate.** `isImeKey` is defined once, in `ui/packages/components/src/lib/ime-key.ts`, and exported from the `@object-ui/components` entry. The grid's `dataTableCellSelection.ts` and `fields/src/widgets/imeKey.ts` now only re-export it. The fields module stays a one-line re-export rather than being deleted because #36039 imports `./imeKey.js`. Each of the two modules keeps its local import path, and the repository has one function body. A test asserts that the function fields uses is the same object the components entry exports. Phase-1 reproduction in real Chromium (CDP `Input.imeSetComposition`, then Enter with keyCode 229, then `Input.insertText`), all three on main 615d995: the grid moved 0-0 to 1-0 and the committed text landed in row 1, and on the last row it appended a line. The date box committed "2026-0" and showed "Not saved". The picker jumped from page 1 to 2 and cleared the box. A plain Enter worked as designed in each. **Files to read first (by risk):** 1. `ui/packages/components/src/index.ts`: the one new entry export (the Clause-② surface). 2. `ui/packages/fields/src/widgets/GridField.tsx`, the `onCellKeyDown` hunk: the guard also stops the arrows during a composition. 3. `ui/packages/fields/src/widgets/imeKey.ts`: now a re-export, not a second definition. **Two-minute check:** `pnpm --filter @object-ui/fields exec vitest run --root ../.. --maxWorkers=2 packages/fields/src/widgets/imeComposition-35996.test.tsx` should report 9 passed. ## Tests `ui/packages/fields/src/widgets/imeComposition-35996.test.tsx` (9 tests). Each widget is driven through both real browser sequences: Chromium/Firefox (compositionstart, keydown Enter with `isComposing: true` and keyCode 229, compositionend) and Safari (compositionstart, compositionend, then the 229 Enter). Each case ends with a plain Enter as the control check, so a guard that swallowed every Enter would fail. There is also one identity test for the single predicate. The existing `imeComposition-35797.test.tsx` predicate cases now run against the shared definition through the re-export. ## Acceptance notes - Overlap with #36039 (S5), rechecked at the new head: still one trivial textual conflict in `GridField.tsx`'s import block. Both sides add `import { isImeKey } from './imeKey.js';` after the `fieldHelpText` import, and git merges that line as common. The conflict is only S5's extra `gridCellPanels.js` import line; keep it. Nothing in `onCellKeyDown` conflicts. - #36054 (S4) has landed and is merged in. The one conflict, in `date-picker/DatePickerField.tsx`, was resolved by taking S4's `textBox` and putting the guard on its Enter handler. `data-table.tsx` needed nothing: it still imports `isImeKey` from `dataTableCellSelection`, and after the merge the repository has exactly one `keyCode === 229` body (`git grep` over non-test `ui/packages/*/src`). - `RecordPickerDialog`'s `handleTableKeyDown` gets no guard: it listens on table rows, which are not editable, so no composition reaches it. ## Verification Every reading below was taken at head `e19af2a8`, which is `b0724f52` merged with main `7dd1a2f6` (including #36054). <details><summary>Package tests and typecheck</summary> - `pnpm --filter @object-ui/fields exec vitest run --root ../.. --maxWorkers=2 packages/fields/` exited 0: Test Files 318 passed, 1 skipped (319); Tests 4794 passed, 7 skipped (4801). - `pnpm --filter @object-ui/components exec vitest run --root ../.. --maxWorkers=2 packages/components/` exited 0: Test Files 502 passed, 1 skipped (503); Tests 4822 passed, 24 skipped (4846). - The 35996 and 35797 pins together: 19/19 passed. - `pnpm --filter @object-ui/components type-check` exited 0. `pnpm --filter @object-ui/fields type-check` exited 0; it runs `tsc --noEmit && tsc -p tsconfig.test.json`, so the new test is type-checked too. </details> <details><summary>Ablation: one run per guard, each failing, each restored</summary> Each ablation went through `scripts/ablation-replace.mjs`, which wraps the run under the verify lock. The test subjects resolve to fields `src/` through relative imports, so no `dist/` rebuild was needed. - GridField `if (isImeKey(e)) return;` replaced with a comment: 4 failed, 5 passed (all four GridField cases). The first attempt queued behind another session's run and timed out (exit 99, NOT MEASURED). The rerun is the reading above. - DatePickerField guard, taken again at `e19af2a8` on S4's `textBox` handler: 2 failed, 7 passed. Restore proven by the tool's own check (blob equals HEAD 90074f0, `git diff HEAD` empty) and by a separate hash comparison. - RecordPickerDialog `|| isImeKey(e)`: 2 failed, 7 passed. The first attempt was refused by the tool before any test ran (its replacement text already occurred in the file), so it was a no-op. The rerun used a unique replacement. - The GridField and RecordPickerDialog readings were taken at `b0724f52`. The merge does not touch either file: its diff against `b0724f52` is empty for both. Restore proven after each run: `git diff HEAD -- FILE` is empty, and the HEAD blob hash equals the on-disk hash (GridField ef12bb6, RecordPickerDialog bd58ecd). </details> <details><summary>Declarations: main vs this head</summary> Both builds used `pnpm --filter @object-ui/components --filter @object-ui/fields build`. The main build came from main `7dd1a2f6`'s sources for both packages, with the new file moved aside; HEAD was then restored, proven by an empty `git diff HEAD` and by blob hashes, and rebuilt. - components: `index.d.ts` gains `export { isImeKey } from './lib/ime-key.js';`, `lib/ime-key.d.ts` is new, and `renderers/complex/dataTableCellSelection.d.ts` now re-exports instead of declaring. Nothing else differs. - fields: `index.d.ts` is byte-identical (`cmp`). Of the 121 emitted `.d.ts`, exactly one differs: `widgets/imeKey.d.ts`, which now reads `export { isImeKey } from '@object-ui/components';` in place of its own `declare function`. It is not reachable from `exports` (`.` only) or from any other `.d.ts`, so the published entry surface is unchanged, but the `dist/` tree is not byte-identical. </details> <details><summary>Derived gate families</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 38 commands, and all 38 exited 0. Reconciliation: `--ran` reports "38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3)". `test:repo` was not run locally; it belongs to CI. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgW85kwjGaz7HqsmEuv --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea58563 commit 8aed508

9 files changed

Lines changed: 262 additions & 31 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/fields': patch
4+
---
5+
6+
Clause-②: yes (widening)
7+
Metadata-protocol: none
8+
Skills-docs: none — no skill teaches the input-method key guard (zero hits for `isImeKey` or `isComposing` under `skills/`); the field behaviour a skill describes is unchanged outside a composition
9+
10+
An Enter that picks a word in a Chinese, Japanese or Korean input method no longer acts in three more field widgets: a line grid's cell no longer moves to the next line or appends one (its arrows no longer move either), the date picker no longer commits the half-typed date, and the record picker's page-jump box no longer jumps and clears itself. Safari's 229 Enter raised just after the composition ends is treated the same way; the next Enter does what it always did.
11+
12+
`@object-ui/components` now exports `isImeKey(event)`, the one "does the input method own this key?" predicate. The list grid and every `@object-ui/fields` widget that reads its own keys ask it, so the copy `@object-ui/fields` kept is gone.

‎ui/packages/components/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export { renderChildren, renderNodeSlot, isEmptyNodeSlot } from './lib/utils';
4141
export { cva } from 'class-variance-authority';
4242
export { getLazyIcon, isLucideIconName, LazyIcon, toKebabIconName } from './lib/lazy-icon';
4343

44+
// The one "does the input method own this key?" predicate (objectstack#35996):
45+
// the list grid and the field widgets of `@object-ui/fields` both ask it.
46+
export { isImeKey } from './lib/ime-key';
47+
4448
// The inline Markdown subset `element:text` draws (objectui#12778). Exported
4549
// because app-shell's marketplace README renderer draws its inline text with
4650
// the same one, so both share the raw-HTML skip and the link-scheme refusal.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* A key the input method owns: pressed while a composition is open
11+
* (`isComposing`, keyCode 229), or the 229 a browser reports for the key that
12+
* ends one (Safari raises the candidate-picking Enter AFTER `compositionend`,
13+
* with `isComposing` already false and keyCode 229). Enter, Esc, Tab, the
14+
* comma, the arrows and Backspace pressed then pick, type or move a candidate
15+
* inside the input method; a control that reads those keys itself must leave
16+
* them alone and act on the next key after the composition ends.
17+
*
18+
* The ONE definition of this question (objectstack#35996). The list grid
19+
* (`data-table`) and every widget in `@object-ui/fields` that reads its own
20+
* keys ask it, so a fix to it reaches all of them at once.
21+
*/
22+
export function isImeKey(e: { nativeEvent: KeyboardEvent; keyCode?: number }): boolean {
23+
return e.nativeEvent.isComposing === true || e.nativeEvent.keyCode === 229 || e.keyCode === 229;
24+
}

‎ui/packages/components/src/renderers/complex/dataTableCellSelection.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414
import type { TableColumn } from '@object-ui/types';
1515

1616
/**
17-
* A key the input method owns: pressed while a composition is open
18-
* (`isComposing`), or the 229 a browser reports for the key that ends one
19-
* (Safari raises the candidate-picking Enter after `compositionend`, as 229).
20-
* Enter, Esc, Tab and the arrows pressed then pick or move a candidate; the
21-
* table must not commit, cancel or move on them.
17+
* The input-method key guard the table asks before it commits, cancels or
18+
* moves on Enter, Esc, Tab or an arrow. Defined once in `../../lib/ime-key`
19+
* (objectstack#35996) and passed through here so the table keeps importing
20+
* its key helpers from one module.
2221
*/
23-
export function isImeKey(e: { nativeEvent: KeyboardEvent; keyCode?: number }): boolean {
24-
return e.nativeEvent.isComposing === true || e.nativeEvent.keyCode === 229 || e.keyCode === 229;
25-
}
22+
export { isImeKey } from '../../lib/ime-key';
2623

2724
/**
2825
* The attribute a link wears when a single click on it still follows it in a

‎ui/packages/fields/src/widgets/GridField.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,10 @@ function GridFieldBody({
11611161

11621162
const onCellKeyDown = useCallback(
11631163
(e: React.KeyboardEvent, rowIdx: number, colIdx: number) => {
1164+
// objectstack#35996 — Enter and the arrows pressed while an input
1165+
// method composes pick or move its candidate: the grid neither moves
1166+
// nor appends a line on them.
1167+
if (isImeKey(e)) return;
11641168
if (e.key === 'Enter' && rowIdx === rows.length - 1 && allowAdd && !isList) {
11651169
e.preventDefault();
11661170
addRow(colIdx);

‎ui/packages/fields/src/widgets/RecordPickerDialog.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { useRecordQuery } from './useRecordQuery.js';
5050
import { isRecordReference, type LookupFilterEntry } from './lookupRecordReference.js';
5151
import { objectResolvesSearch } from './searchOffer.js';
5252
import { PHONE_TOUCH_HEIGHT } from './touchTarget.js';
53+
import { isImeKey } from './imeKey.js';
5354
// The one place a lookup column's display value is decided — shared with the
5455
// inline dropdown in LookupField so a single `lookupColumns` declaration
5556
// cannot render two different ways (objectui#5492).
@@ -974,7 +975,9 @@ export function RecordPickerDialog({
974975
// Page jump handler
975976
const handlePageJump = useCallback(
976977
(e: React.KeyboardEvent<HTMLInputElement>) => {
977-
if (e.key !== 'Enter') return;
978+
// objectstack#35996 — an Enter that picks an input-method candidate
979+
// neither jumps nor clears the box under the composition.
980+
if (e.key !== 'Enter' || isImeKey(e)) return;
978981
const page = parseInt(pageJumpValue, 10);
979982
if (!isNaN(page) && page >= 1 && page <= totalPages) {
980983
setCurrentPage(page);

‎ui/packages/fields/src/widgets/date-picker/DatePickerField.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
fromLocalDay,
4545
} from './localeDateText.js';
4646
import { useFieldTranslation } from '../useFieldTranslation.js';
47+
import { isImeKey } from '../imeKey.js';
4748

4849
/**
4950
* The `date` and date-time controls of the form field widgets
@@ -266,6 +267,9 @@ function TemporalPicker({
266267
domProps.onBlur?.(e);
267268
}}
268269
onKeyDown={(e) => {
270+
// objectstack#35996 — an Enter that picks an input-method candidate
271+
// does not commit the half-typed text.
272+
if (isImeKey(e)) return;
269273
if (e.key === 'Enter') {
270274
// Commit, and keep a bare Enter from submitting the form with
271275
// the text not yet read.
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* An Enter the input method owns does only what the input method does with it
11+
* (objectstack#35996), in the three widgets objectstack#35797 left out:
12+
*
13+
* - `GridField`: a cell's Enter moves to the next line, and on the last line
14+
* appends one; the composed text then landed in the wrong line.
15+
* - `DatePickerField`: Enter commits the typed date text.
16+
* - `RecordPickerDialog`: Enter in the page-jump box jumps and clears it.
17+
*
18+
* Each widget is driven through the two sequences browsers really send
19+
* (Chromium / Firefox: the picking keydown inside the composition, with
20+
* `isComposing: true` and keyCode 229; Safari: the 229 keydown after
21+
* `compositionend`), and each case ends with the control: a plain Enter does
22+
* what the widget always did, so a guard that swallowed every Enter goes red.
23+
*
24+
* The predicate itself is pinned once, in `imeComposition-35797.test.tsx`;
25+
* `./imeKey` is the pass-through of the one definition on the
26+
* `@object-ui/components` entry, which the identity case below pins.
27+
*/
28+
29+
import * as React from 'react';
30+
import { describe, it, expect, vi, afterEach } from 'vitest';
31+
import { render, screen, cleanup, waitFor, fireEvent } from '@testing-library/react';
32+
import '@testing-library/jest-dom';
33+
34+
import { isImeKey as componentsIsImeKey } from '@object-ui/components';
35+
import { isImeKey } from './imeKey';
36+
import { GridField } from './GridField';
37+
import { DatePickerField } from './date-picker/DatePickerField';
38+
import { RecordPickerDialog } from './RecordPickerDialog';
39+
import { getCellRenderer } from '../index';
40+
41+
/** The keydown that picks a candidate while the composition is open. */
42+
const COMPOSING_ENTER = { key: 'Enter', code: 'Enter', keyCode: 229, which: 229, isComposing: true } as const;
43+
/** Safari's candidate-picking Enter, raised after `compositionend`. */
44+
const SAFARI_POST_COMPOSITION_ENTER = { key: 'Enter', code: 'Enter', keyCode: 229, which: 229, isComposing: false } as const;
45+
/** An Enter the input method does not own. */
46+
const PLAIN_ENTER = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13 } as const;
47+
48+
type Composer = (el: HTMLElement, text: string) => void;
49+
const type = (el: HTMLElement, text: string) => fireEvent.change(el, { target: { value: text } });
50+
51+
/** Chromium / Firefox: the picking keydown arrives inside the composition. */
52+
const composeChromium: Composer = (el, text) => {
53+
fireEvent.compositionStart(el, { data: '' });
54+
type(el, text);
55+
fireEvent.keyDown(el, COMPOSING_ENTER);
56+
fireEvent.compositionEnd(el, { data: text });
57+
};
58+
59+
/** Safari: the composition has ended when the picking keydown arrives. */
60+
const composeSafari: Composer = (el, text) => {
61+
fireEvent.compositionStart(el, { data: '' });
62+
type(el, text);
63+
fireEvent.compositionEnd(el, { data: text });
64+
fireEvent.keyDown(el, SAFARI_POST_COMPOSITION_ENTER);
65+
};
66+
67+
const BROWSERS = [['Chromium', composeChromium], ['Safari', composeSafari]] as const;
68+
69+
afterEach(() => {
70+
cleanup();
71+
vi.restoreAllMocks();
72+
});
73+
74+
describe('one IME-key predicate in the repository (objectstack#35996)', () => {
75+
it('the fields widgets ask the very function the components entry exports', () => {
76+
expect(isImeKey).toBe(componentsIsImeKey);
77+
});
78+
});
79+
80+
describe('GridField — an IME Enter in a cell neither moves nor appends a line (objectstack#35996)', () => {
81+
const FIELD = { name: 'lines', type: 'grid', columns: [{ name: 'desc', type: 'text', label: 'Desc' }] } as never;
82+
83+
function mountGrid() {
84+
const onChange = vi.fn();
85+
const Host = () => {
86+
const [value, setValue] = React.useState<Record<string, unknown>[]>([{ desc: 'a' }, { desc: 'b' }]);
87+
return (
88+
<GridField
89+
value={value}
90+
onChange={(v: Record<string, unknown>[]) => {
91+
onChange(v);
92+
setValue(v);
93+
}}
94+
field={FIELD}
95+
/>
96+
);
97+
};
98+
const { container } = render(<Host />);
99+
const cell = (row: number) => container.querySelector(`[data-cell="${row}-0"]`) as HTMLInputElement | null;
100+
return { cell, onChange };
101+
}
102+
103+
for (const [browser, compose] of BROWSERS) {
104+
it(`${browser}: the candidate-picking Enter keeps focus on its line; the next Enter moves down`, () => {
105+
const { cell } = mountGrid();
106+
cell(0)!.focus();
107+
compose(cell(0)!, '你');
108+
expect(document.activeElement).toBe(cell(0));
109+
expect(cell(0)!.value).toBe('你');
110+
111+
fireEvent.keyDown(cell(0)!, PLAIN_ENTER);
112+
expect(document.activeElement).toBe(cell(1));
113+
});
114+
115+
it(`${browser}: on the last line the candidate-picking Enter appends no line; the next Enter does`, async () => {
116+
const { cell, onChange } = mountGrid();
117+
cell(1)!.focus();
118+
compose(cell(1)!, '好');
119+
// The composed text is the one write; no third line.
120+
expect(onChange.mock.calls.every(([rows]) => (rows as unknown[]).length === 2)).toBe(true);
121+
expect(cell(2)).toBeNull();
122+
expect(document.activeElement).toBe(cell(1));
123+
124+
fireEvent.keyDown(cell(1)!, PLAIN_ENTER);
125+
expect(onChange).toHaveBeenLastCalledWith([expect.anything(), expect.anything(), expect.anything()]);
126+
await waitFor(() => expect(document.activeElement).toBe(cell(2)));
127+
});
128+
}
129+
});
130+
131+
describe('DatePickerField — an IME Enter does not commit the typed text (objectstack#35996)', () => {
132+
const FIELD = { name: 'close_date', type: 'date' } as never;
133+
134+
for (const [browser, compose] of BROWSERS) {
135+
it(`${browser}: the candidate-picking Enter commits nothing; the next Enter commits the date`, () => {
136+
const onChange = vi.fn();
137+
render(<DatePickerField value="" onChange={onChange} field={FIELD} />);
138+
const input = screen.getByRole('textbox') as HTMLInputElement;
139+
input.focus();
140+
compose(input, '10/16/2026');
141+
expect(onChange).not.toHaveBeenCalled();
142+
expect(input).not.toHaveAttribute('aria-invalid', 'true');
143+
expect(input.value).toBe('10/16/2026');
144+
145+
fireEvent.keyDown(input, PLAIN_ENTER);
146+
expect(onChange).toHaveBeenLastCalledWith('2026-10-16');
147+
});
148+
}
149+
});
150+
151+
describe('RecordPickerDialog — an IME Enter in the page-jump box neither jumps nor clears it (objectstack#35996)', () => {
152+
const USERS = Array.from({ length: 12 }, (_, i) => {
153+
const n = String(i + 1).padStart(2, '0');
154+
return { id: `u${n}`, name: `User ${n}` };
155+
});
156+
const FIELDS = { name: { type: 'text', label: 'Name' } };
157+
158+
function mountPicker() {
159+
const dataSource = {
160+
find: vi.fn(async (_o: string, params?: { $skip?: number; $top?: number }) => {
161+
const skip = params?.$skip ?? 0;
162+
const top = params?.$top ?? USERS.length;
163+
return { data: USERS.slice(skip, skip + top), total: USERS.length };
164+
}),
165+
findOne: vi.fn(async (_o: string, id: string) => USERS.find((r) => r.id === id) ?? null),
166+
getObjectSchema: vi.fn(async () => ({ name: 'sys_user', fields: FIELDS })),
167+
} as any;
168+
render(
169+
<RecordPickerDialog
170+
open
171+
onOpenChange={() => {}}
172+
dataSource={dataSource}
173+
objectName="sys_user"
174+
columns={['name']}
175+
fieldsMeta={FIELDS}
176+
cellRenderer={getCellRenderer}
177+
onSelect={() => {}}
178+
/>,
179+
);
180+
}
181+
const rows = () => document.querySelectorAll('[data-testid^="record-row-"]');
182+
183+
for (const [browser, compose] of BROWSERS) {
184+
it(`${browser}: the candidate-picking Enter stays on page 1 and keeps the text; the next Enter jumps`, async () => {
185+
mountPicker();
186+
await waitFor(() => expect(rows()).toHaveLength(10));
187+
const jump = screen.getByTestId('record-picker-page-jump') as HTMLInputElement;
188+
jump.focus();
189+
compose(jump, '2');
190+
expect(jump.value).toBe('2');
191+
expect(jump).toHaveAttribute('placeholder', '1');
192+
193+
fireEvent.keyDown(jump, PLAIN_ENTER);
194+
await waitFor(() => expect(rows()).toHaveLength(2));
195+
expect(jump).toHaveAttribute('placeholder', '2');
196+
expect(jump.value).toBe('');
197+
});
198+
}
199+
});

‎ui/packages/fields/src/widgets/imeKey.ts‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,10 @@
77
*/
88

99
/**
10-
* A key the input method owns: pressed while a composition is open
11-
* (`isComposing`, keyCode 229), or the 229 a browser reports for the key that
12-
* ends one (Safari raises the candidate-picking Enter AFTER `compositionend`,
13-
* with `isComposing` already false and keyCode 229). Enter, the comma, the
14-
* arrows and Backspace pressed then pick, type or move a candidate inside the
15-
* input method; a widget that reads those keys itself must leave them alone
16-
* and act on the next key after the composition ends.
17-
*
18-
* The one predicate every widget in this package that reads its own keys asks
19-
* (`TagsField`, and the search boxes of `LookupField` and `PeoplePicker`), so
20-
* they cannot drift into three answers. It is package-internal on purpose:
21-
* nothing re-exports it from this package's entry.
22-
*
23-
* ⚠️ It has one twin outside this package: `isImeKey` in
24-
* `@object-ui/components` (`renderers/complex/dataTableCellSelection.ts`),
25-
* the list grid's own key guard. That one is not on the components entry,
26-
* and importing it here would add an export to a published entry, so this is
27-
* a second definition of the same question. A change to one is a change to
28-
* both; nothing checks that the two still agree.
10+
* The input-method key guard every widget in this package that reads its own
11+
* keys asks. It is NOT defined here: the one definition is `isImeKey` on the
12+
* `@object-ui/components` entry (objectstack#35996), which the list grid asks
13+
* too. This module only passes it through so the widgets keep one local
14+
* import path; it is not re-exported from this package's entry.
2915
*/
30-
export function isImeKey(e: { nativeEvent: KeyboardEvent; keyCode?: number }): boolean {
31-
return e.nativeEvent.isComposing === true || e.nativeEvent.keyCode === 229 || e.keyCode === 229;
32-
}
16+
export { isImeKey } from '@object-ui/components';

0 commit comments

Comments
 (0)