diff --git a/.changeset/26579-flow-screen-platform-controls.md b/.changeset/26579-flow-screen-platform-controls.md new file mode 100644 index 00000000000..e792a5d2b4f --- /dev/null +++ b/.changeset/26579-flow-screen-platform-controls.md @@ -0,0 +1,17 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(app-shell): flow screen date, date-time and boolean fields use the platform controls + +Clause-②: no +Metadata-protocol: none + +A screen flow's input screen was the last form surface still drawing the browser's native date input, so a `date` field showed the machine's format (`mm/dd/yyyy` under a Chinese console), a `datetime` field was a bare text box, and a `boolean` field was a lone checkbox on the line under its label, which read like an empty radio button. + +What changes: + +- A `date` or `datetime` screen field is now the record form's date picker: a text box in the display locale's format, a calendar popover, a clear button and the today / tomorrow shortcuts. The value it hands the flow is the stored shape: `YYYY-MM-DD` for a date and an ISO instant for a date-time, and `''` when cleared, as the native date input wrote. +- A `boolean` (or `checkbox`) screen field is now the inline row the action-parameter dialog draws: the checkbox with its label beside it, and the help text under the row. + +What to do: nothing. No flow metadata changes. diff --git a/ui/packages/app-shell/src/views/ScreenView.boundHelpReference-9248.test.tsx b/ui/packages/app-shell/src/views/ScreenView.boundHelpReference-9248.test.tsx index e849d3116e9..659720da376 100644 --- a/ui/packages/app-shell/src/views/ScreenView.boundHelpReference-9248.test.tsx +++ b/ui/packages/app-shell/src/views/ScreenView.boundHelpReference-9248.test.tsx @@ -54,10 +54,10 @@ describe('objectui#9248 — `min` / `max` land on the numeric input', () => { expect(input).not.toHaveAttribute('max'); }); - it('a bound declared on a non-numeric input is not written onto it (a date input would read it as a date)', () => { - const { container } = renderScreen([{ name: 'due', label: 'Due', type: 'date', min: 1, max: 10 }]); - const input = container.querySelector('#ff-due'); - expect(input).toHaveAttribute('type', 'date'); + it('a bound declared on a non-numeric input is not written onto it (the date picker reads no numeric bound)', async () => { + renderScreen([{ name: 'due', label: 'Due', type: 'date', min: 1, max: 10 }]); + const input = await screen.findByRole('textbox', { name: 'Due' }); + expect(input).toHaveAttribute('id', 'ff-due'); expect(input).not.toHaveAttribute('min'); expect(input).not.toHaveAttribute('max'); }); @@ -123,7 +123,7 @@ describe('objectui#9248 — `inlineHelpText` is drawn under the control and desc expect(screen.getByText('Shown below')).toBeVisible(); }); - it('describes every control arm, not only the text input', () => { + it('describes every control arm, not only the text input', async () => { renderScreen([ { name: 'body', label: 'Body', type: 'textarea', inlineHelpText: 'Body help' }, { name: 'agree', label: 'Agree', type: 'boolean', inlineHelpText: 'Agree help' }, @@ -131,7 +131,7 @@ describe('objectui#9248 — `inlineHelpText` is drawn under the control and desc { name: 'qty', label: 'Qty', type: 'number', inlineHelpText: 'Qty help' }, ]); expect(screen.getByRole('textbox', { name: 'Body' })).toHaveAccessibleDescription('Body help'); - expect(screen.getByRole('checkbox', { name: 'Agree' })).toHaveAccessibleDescription('Agree help'); + expect(await screen.findByRole('checkbox', { name: 'Agree' })).toHaveAccessibleDescription('Agree help'); expect(screen.getByRole('combobox', { name: 'Kind' })).toHaveAccessibleDescription('Kind help'); expect(screen.getByRole('spinbutton', { name: 'Qty' })).toHaveAccessibleDescription('Qty help'); }); @@ -185,7 +185,7 @@ describe('objectui#9248 — a `type: \'lookup\'` field resolves its picker from }); describe('objectui#9248 — CONTROL: a field declaring none of the keys renders as before', () => { - it('no bound, no description, no help element, no picker', () => { + it('no bound, no description, no help element, no picker', async () => { const { container } = renderScreen([ { name: 'qty', label: 'Qty', type: 'number' }, { name: 'title', label: 'Title', type: 'text', placeholder: 'Type here' }, @@ -193,19 +193,21 @@ describe('objectui#9248 — CONTROL: a field declaring none of the keys renders { name: 'acct', label: 'Account', type: 'text' }, ]); const qty = screen.getByRole('spinbutton', { name: 'Qty' }); + const agree = await screen.findByRole('checkbox', { name: 'Agree' }); expect(qty).not.toHaveAttribute('min'); expect(qty).not.toHaveAttribute('max'); for (const control of [ qty, screen.getByRole('textbox', { name: 'Title' }), - screen.getByRole('checkbox', { name: 'Agree' }), + agree, screen.getByRole('textbox', { name: 'Account' }), ]) { expect(control).not.toHaveAttribute('aria-describedby'); } expect(container.querySelector('[id$="-help"]')).toBeNull(); expect(container.querySelector('[data-testid^="lookup-trigger"]')).toBeNull(); - // Each field is still exactly a label and its control. + // Each stacked field is still exactly a label and its control (the + // boolean is the inline row since objectstack#26579). for (const block of container.querySelectorAll('.space-y-1\\.5')) { expect(block.children).toHaveLength(2); } diff --git a/ui/packages/app-shell/src/views/ScreenView.platformControls-26579.test.tsx b/ui/packages/app-shell/src/views/ScreenView.platformControls-26579.test.tsx new file mode 100644 index 00000000000..231ebc1b9b6 --- /dev/null +++ b/ui/packages/app-shell/src/views/ScreenView.platformControls-26579.test.tsx @@ -0,0 +1,166 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#26579 — a flow screen's `date` / `datetime` and `boolean` fields + * draw the platform controls the record form and `ActionParamDialog` draw. + * + * A date field was the browser's native input (`mm/dd/yyyy` under zh-CN), a + * date-time field a bare text box, and a boolean a lone checkbox on the line + * under its label. Now a date or date-time field is the record form's picker + * in the display locale's format, writing the stored shape the native input + * wrote, and a boolean is `ActionParamDialog`'s inline row: the checkbox with + * its label beside it and the help text under the row. + */ + +import { describe, it, expect, afterEach, vi } from 'vitest'; +import { render, screen, cleanup, fireEvent } from '@testing-library/react'; +import { I18nProvider } from '@object-ui/i18n'; +// Module scope, per AGENTS.md 测试纪律: the date, date-time and boolean arms +// reach their widgets through `React.lazy` factories inside `@object-ui/fields`; +// importing the barrel here resolves them before any test's `findBy` budget. +import '@object-ui/fields'; +import { ScreenView, type ScreenSpec } from './ScreenView'; + +afterEach(cleanup); + +function specOf(fields: ScreenSpec['fields']): ScreenSpec { + return { nodeId: 'n1', title: 'Step', fields } as ScreenSpec; +} + +function renderScreen( + fields: ScreenSpec['fields'], + extra: { values?: Record; onValueChange?: (name: string, v: unknown) => void } = {}, +) { + return render( + {})} />, + ); +} + +const typeAndCommit = (input: HTMLElement, text: string) => { + fireEvent.change(input, { target: { value: text } }); + fireEvent.blur(input); +}; + +describe('objectstack#26579 — a `date` screen field is the platform picker', () => { + it('draws the locale-format text box and calendar, never input[type=date]', async () => { + const { container } = renderScreen([{ name: 'start', label: 'Start', type: 'date' }], { values: { start: '2026-10-16' } }); + const input = await screen.findByRole('textbox', { name: 'Start' }); + expect(container.querySelector('input[type="date"]')).toBeNull(); + expect(input.closest('[data-slot="date-picker"]')).not.toBeNull(); + expect(input).toHaveValue('10/16/2026'); + expect(screen.getByTestId('date-picker-trigger')).toBeTruthy(); + }); + + it('a zh session reads and shows the zh format', async () => { + render( + + {}} /> + , + ); + const input = await screen.findByRole('textbox', { name: 'Start' }); + expect(input).toHaveValue('2026/10/16'); + expect(input).toHaveAttribute('placeholder', 'YYYY/MM/DD'); + }); + + it('typed text is written as the ISO day the native input wrote', async () => { + const onValueChange = vi.fn(); + renderScreen([{ name: 'start', label: 'Start', type: 'date' }], { onValueChange }); + typeAndCommit(await screen.findByRole('textbox', { name: 'Start' }), '10/20/2026'); + expect(onValueChange).toHaveBeenCalledWith('start', '2026-10-20'); + }); + + it('clearing writes the empty string, as the native input did', async () => { + const onValueChange = vi.fn(); + renderScreen([{ name: 'start', label: 'Start', type: 'date' }], { values: { start: '2026-10-16' }, onValueChange }); + await screen.findByRole('textbox', { name: 'Start' }); + fireEvent.click(screen.getByTestId('date-picker-clear')); + expect(onValueChange).toHaveBeenCalledWith('start', ''); + }); + + it('keeps the required state and the help text on the control', async () => { + renderScreen([{ name: 'start', label: 'Start', type: 'date', required: true, inlineHelpText: 'Start help' }]); + const input = await screen.findByRole('textbox', { name: 'Start' }); + expect(input).toHaveAttribute('aria-required', 'true'); + expect(input).toHaveAccessibleDescription('Start help'); + }); +}); + +describe('objectstack#26579 — a `datetime` screen field is the platform date-time picker', () => { + it('draws the picker and writes an ISO instant', async () => { + const onValueChange = vi.fn(); + const { container } = renderScreen([{ name: 'remind', label: 'Remind', type: 'datetime' }], { onValueChange }); + const input = await screen.findByRole('textbox', { name: 'Remind' }); + expect(input.closest('[data-slot="date-picker"]')).not.toBeNull(); + expect(container.querySelector('input[type="datetime-local"]')).toBeNull(); + typeAndCommit(input, '10/16/2026 14:30'); + expect(onValueChange).toHaveBeenCalledWith('remind', new Date(2026, 9, 16, 14, 30).toISOString()); + }); +}); + +describe('objectstack#26579 — a `boolean` screen field is the inline checkbox row', () => { + it('draws the label BESIDE the checkbox, in one row', async () => { + renderScreen([{ name: 'estimate', label: 'Estimated amount', type: 'boolean' }]); + const box = await screen.findByRole('checkbox', { name: 'Estimated amount' }); + const label = screen.getByText('Estimated amount'); + const row = label.parentElement as HTMLElement; + expect(row).toHaveClass('flex'); + expect(row.contains(box)).toBe(true); + // The control comes first, the label after it. + expect(box.compareDocumentPosition(label) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + }); + + it('a `checkbox` widget hint draws the same row', async () => { + renderScreen([{ name: 'submit_now', label: 'Submit now', type: 'checkbox' }]); + const box = await screen.findByRole('checkbox', { name: 'Submit now' }); + expect((screen.getByText('Submit now').parentElement as HTMLElement).contains(box)).toBe(true); + }); + + it('ticking answers `true` and unticking `false`; clicking the label toggles it', async () => { + const onValueChange = vi.fn(); + const { rerender } = renderScreen([{ name: 'estimate', label: 'Estimated amount', type: 'boolean' }], { onValueChange }); + fireEvent.click(await screen.findByRole('checkbox', { name: 'Estimated amount' })); + expect(onValueChange).toHaveBeenLastCalledWith('estimate', true); + rerender( + , + ); + expect(screen.getByRole('checkbox', { name: 'Estimated amount' })).toBeChecked(); + fireEvent.click(screen.getByText('Estimated amount')); + expect(onValueChange).toHaveBeenLastCalledWith('estimate', false); + }); + + it('only a real `true` is checked', async () => { + renderScreen([{ name: 'estimate', label: 'Estimated amount', type: 'boolean' }], { values: { estimate: 'true' } }); + expect(await screen.findByRole('checkbox', { name: 'Estimated amount' })).not.toBeChecked(); + }); + + it('carries the required state and marker, and its help text under the row describes it', async () => { + renderScreen([{ name: 'estimate', label: 'Estimated amount', type: 'boolean', required: true, inlineHelpText: 'Tick when estimated' }]); + const box = await screen.findByRole('checkbox', { name: 'Estimated amount' }); + expect(box).toHaveAttribute('aria-required', 'true'); + expect(box).toHaveAccessibleDescription('Tick when estimated'); + const label = screen.getByText('Estimated amount'); + expect(label.querySelector('[data-required-marker="true"]')).not.toBeNull(); + const help = screen.getByText('Tick when estimated'); + expect(help.parentElement?.contains(label.parentElement)).toBe(true); + expect(label.parentElement?.contains(help)).toBe(false); + }); + + it('the widget draws no second label for the host-named control', async () => { + const { container } = renderScreen([{ name: 'estimate', label: 'Estimated amount', type: 'boolean' }]); + await screen.findByRole('checkbox', { name: 'Estimated amount' }); + expect(container.querySelectorAll('label[for="ff-estimate"]')).toHaveLength(1); + }); + + it('CONTROL — a boolean field declaring `options` stays a select with its label above', () => { + const { container } = renderScreen([ + { name: 'flag', label: 'Flag', type: 'boolean', options: [{ label: 'Yes', value: true }, { label: 'No', value: false }] }, + ]); + expect(screen.getByRole('combobox', { name: 'Flag' })).toBeTruthy(); + expect(screen.queryByRole('checkbox')).toBeNull(); + expect(container.querySelector('.space-y-1\\.5')?.children).toHaveLength(2); + }); +}); diff --git a/ui/packages/app-shell/src/views/ScreenView.requiredMarker-10367.test.tsx b/ui/packages/app-shell/src/views/ScreenView.requiredMarker-10367.test.tsx index 076e9a5795f..f2b85b61ff7 100644 --- a/ui/packages/app-shell/src/views/ScreenView.requiredMarker-10367.test.tsx +++ b/ui/packages/app-shell/src/views/ScreenView.requiredMarker-10367.test.tsx @@ -22,6 +22,10 @@ import { describe, it, expect, afterEach } from 'vitest'; import { render, screen, cleanup } from '@testing-library/react'; +// Module scope, per AGENTS.md 测试纪律: the boolean arm reaches `BooleanField` +// through a `React.lazy` factory inside `@object-ui/fields`; importing the +// barrel here resolves that factory before any test's `findBy` budget starts. +import '@object-ui/fields'; import { ScreenView, type ScreenSpec } from './ScreenView'; afterEach(cleanup); @@ -48,7 +52,7 @@ describe('objectui#10367 — ScreenView keeps the required `*` out of the access expect(marker).toHaveAttribute('aria-hidden', 'true'); }); - it('every other control arm carries aria-required and a name without `*`', () => { + it('every other control arm carries aria-required and a name without `*`', async () => { renderScreen([ { name: 'note', label: 'Note', type: 'textarea', required: true }, { name: 'agree', label: 'Agree', type: 'boolean', required: true }, @@ -59,7 +63,7 @@ describe('objectui#10367 — ScreenView keeps the required `*` out of the access expect(note).toHaveAttribute('aria-required', 'true'); expect(note).not.toHaveAttribute('required'); - const agree = screen.getByRole('checkbox', { name: 'Agree' }); + const agree = await screen.findByRole('checkbox', { name: 'Agree' }); expect(agree).toHaveAttribute('aria-required', 'true'); expect(agree).not.toHaveAttribute('required'); @@ -67,7 +71,7 @@ describe('objectui#10367 — ScreenView keeps the required `*` out of the access expect(kind).toHaveAttribute('aria-required', 'true'); }); - it('CONTROL — an optional field shows no marker and carries no aria-required', () => { + it('CONTROL — an optional field shows no marker and carries no aria-required', async () => { const { container } = renderScreen([ { name: 'title', label: 'Title', type: 'text' }, { name: 'agree', label: 'Agree', type: 'boolean' }, @@ -77,6 +81,6 @@ describe('objectui#10367 — ScreenView keeps the required `*` out of the access const input = screen.getByRole('textbox', { name: 'Title' }); expect(input).not.toBeRequired(); expect(input).not.toHaveAttribute('aria-required'); - expect(screen.getByRole('checkbox', { name: 'Agree' })).not.toHaveAttribute('aria-required'); + expect(await screen.findByRole('checkbox', { name: 'Agree' })).not.toHaveAttribute('aria-required'); }); }); diff --git a/ui/packages/app-shell/src/views/ScreenView.tsx b/ui/packages/app-shell/src/views/ScreenView.tsx index c375460d72e..6e3f3192eb1 100644 --- a/ui/packages/app-shell/src/views/ScreenView.tsx +++ b/ui/packages/app-shell/src/views/ScreenView.tsx @@ -69,6 +69,21 @@ * The field takes no input. It is never seeded into the collected values * ({@link initialScreenValues}) and never posted ({@link screenResumeValues}): * the engine refuses a resume that carries any value under its name. + * + * ## `date`, `datetime` and `boolean` are the platform controls (objectstack#26579) + * + * A `date` / `datetime` field is the record form's picker (`DatePickerField` / + * `DateTimePickerField`, objectui#12622): a text box in the display locale's + * format, a calendar popover and a clear button, reached through + * `getLazyFieldWidget` as `ActionParamDialog`'s date params reach it. The + * value it writes is the stored shape the native inputs wrote — `YYYY-MM-DD` + * for a date, an ISO instant for a date-time, `''` when cleared — so the + * runner's `required` check and the resume bag read it unchanged. + * + * A `boolean` (or `checkbox`) field is `ActionParamDialog`'s inline row: the + * form's `BooleanField` in its checkbox face, with the label BESIDE the control + * and the help text under the row. The generic layout put the label on one line + * and a lone checkbox on the next, which read as an empty radio button. */ import { Suspense } from 'react'; import { Link, useInRouterContext, useParams } from 'react-router-dom'; @@ -76,7 +91,6 @@ import { Input, Label, Textarea, - Checkbox, Select, SelectTrigger, SelectValue, @@ -102,6 +116,24 @@ const LookupFieldWidget = getLazyFieldWidget('lookup'); /** The object form's upload widget (`FileField`), resolved the same way. */ const FileFieldWidget = getLazyFieldWidget('file'); +/** The object form's date and date-time pickers (objectui#12622), resolved the same way. */ +const DateFieldWidget = getLazyFieldWidget('date'); +const DateTimeFieldWidget = getLazyFieldWidget('datetime'); + +/** The object form's boolean control (`BooleanField`), resolved the same way. */ +const BooleanFieldWidget = getLazyFieldWidget('boolean'); + +/** + * Whether a screen field draws the boolean control, and so the inline row. + * A boolean field that declares `options` is a select, as {@link ScreenFieldInput} + * draws it, so it keeps the label above. + */ +function isBooleanScreenField(field: ScreenFieldSpec): boolean { + const kind = (field.type || '').toLowerCase(); + if (kind !== 'boolean' && kind !== 'checkbox') return false; + return !(Array.isArray(field.options) && field.options.length > 0); +} + /** * Whether a screen field is the read-only record link. Matched exactly, as the * spec's refinement and the engine's resume rule match it, so the console never @@ -390,6 +422,36 @@ export function ScreenView({ screen, values, onValueChange, dataSource, objects, // placeholder (which the browser clears on the first keystroke), and // the control names it in `aria-describedby` so it is announced too. const helpId = f.inlineHelpText ? screenFieldHelpId(f.name) : undefined; + const input = ( + onValueChange(f.name, v)} + describedBy={helpId} + dataSource={dataSource} + objects={objects} + /> + ); + // The boolean control sits BESIDE its label, `ActionParamDialog`'s + // inline row; the help text lines up under the label. + if (isBooleanScreenField(f)) { + return ( +
+
+ {input} + +
+ {helpId && ( +

{f.inlineHelpText}

+ )} +
+ ); + } return (
- onValueChange(f.name, v)} - describedBy={helpId} - dataSource={dataSource} - objects={objects} - /> + {input} {helpId && (

{f.inlineHelpText}

)} @@ -537,17 +592,51 @@ export function ScreenFieldInput({ ); } + // The form's `BooleanField` in its checkbox face, as `ActionParamDialog`'s + // boolean params draw it (objectstack#26579); {@link ScreenView} lays the + // label beside it. The host owns the id, so the widget draws no `sr-only` + // label of its own. Only a real `true` is checked, and a tick answers a + // real boolean. if (kind === 'boolean' || kind === 'checkbox') { - return onChange(c === true)} />; + return ( + + ); + } + // The record form's date / date-time picker (objectstack#26579), in the + // display locale's format instead of the browser's native input. It writes + // the stored shape the native input wrote, so nothing downstream changes. + if (kind === 'date' || kind === 'datetime') { + const Picker = kind === 'date' ? DateFieldWidget : DateTimeFieldWidget; + return ( + + ); } if (kind === 'textarea' || kind === 'markdown') { return