Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/26579-flow-screen-platform-controls.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down Expand Up @@ -123,15 +123,15 @@ 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' },
{ name: 'kind', label: 'Kind', options: [{ label: 'A', value: 'a' }], inlineHelpText: 'Kind help' },
{ 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');
});
Expand Down Expand Up @@ -185,27 +185,29 @@ 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' },
{ name: 'agree', label: 'Agree', type: 'boolean' },
{ 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, unknown>; onValueChange?: (name: string, v: unknown) => void } = {},
) {
return render(
<ScreenView screen={specOf(fields)} values={extra.values ?? {}} onValueChange={extra.onValueChange ?? (() => {})} />,
);
}

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(
<I18nProvider config={{ defaultLanguage: 'zh', detectBrowserLanguage: false }} persistLanguage={false}>
<ScreenView screen={specOf([{ name: 'start', label: 'Start', type: 'date' }])} values={{ start: '2026-10-16' }} onValueChange={() => {}} />
</I18nProvider>,
);
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(
<ScreenView
screen={specOf([{ name: 'estimate', label: 'Estimated amount', type: 'boolean' }])}
values={{ estimate: true }}
onValueChange={onValueChange}
/>,
);
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 },
Expand All @@ -59,15 +63,15 @@ 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');

const kind = screen.getByRole('combobox', { name: 'Kind' });
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' },
Expand All @@ -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');
});
});
Loading
Loading