From 9f114112bf84f33290831a4544c17b5b99cf8123 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 14:23:50 +0000 Subject: [PATCH 1/4] fix(fields): boolean draws a checkbox and toggle a switch, on the canvas and in the form One type-to-widget resolution, resolveBooleanControl, read by BooleanField (record form, inline edit) and the Studio canvas preview. Claude-Session: https://claude.ai/code/session_01Utp6CY2n1JmZZKrHgtp9jC Co-authored-by: Claude --- .../studio-design/ObjectFormDesigner.tsx | 16 ++++- ui/packages/fields/src/field-type-alias.ts | 2 +- ui/packages/fields/src/index.tsx | 1 + .../fields/src/widgets/BooleanField.tsx | 14 +++-- .../fields/src/widgets/booleanControl.ts | 60 +++++++++++++++++++ 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 ui/packages/fields/src/widgets/booleanControl.ts diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx index 601c9d1c708..80e48700eec 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.tsx @@ -38,6 +38,7 @@ import { GripVertical, Plus, Trash2, ChevronUp, ChevronDown, ChevronsUpDown, Pan import { cn } from '@object-ui/components'; import { inferColumns, containerGridColsFor, isWideFieldType } from '@object-ui/plugin-form'; import { toFormFieldType } from './formFieldType.js'; +import { resolveBooleanControl } from '@object-ui/fields'; import { readFields, writeFields, @@ -310,14 +311,23 @@ function FieldControlPreview({ type }: { type: string }): React.ReactElement { case 'json': case 'code': return
; + // objectstack#27519 — the runtime form's own answer, not a canvas copy: + // `boolean` previews a checkbox and `toggle` a switch, as the type picker + // promises. `toggle` used to fall to the text box below, and `boolean` + // drew the switch pill. case 'boolean': + case 'toggle': case 'checkbox': - case 'switch': + case 'switch': { + const control = resolveBooleanControl({ type }); return ( -
- +
+ {control === 'checkbox' + ? + : }
); + } case 'number': case 'currency': case 'percent': diff --git a/ui/packages/fields/src/field-type-alias.ts b/ui/packages/fields/src/field-type-alias.ts index 176c2f8062d..a5b6a50c462 100644 --- a/ui/packages/fields/src/field-type-alias.ts +++ b/ui/packages/fields/src/field-type-alias.ts @@ -129,7 +129,7 @@ export function mapFieldTypeToFormType( // Boolean boolean: 'field:boolean', - toggle: 'field:boolean', // toggle is a boolean rendered as a switch + toggle: 'field:boolean', // one widget; it draws a switch for toggle (resolveBooleanControl) // Selection fields select: 'field:select', diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 2af51d1dfc3..b16fa435531 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -4271,6 +4271,7 @@ setFieldReadFaceResolver(resolveDeclaredFieldFace); // `mapFieldTypeToFormType` moved to './field-type-alias' (re-exported below) so // FieldEditWidget can resolve spec aliases without importing this barrel. export { mapFieldTypeToFormType } from './field-type-alias.js'; +export { resolveBooleanControl, type BooleanControl } from './widgets/booleanControl.js'; import { mapFieldTypeToFormType } from './field-type-alias.js'; // `isRetiredFieldType` is the gate the maintainer ruled onto THIS package's // surface (objectui#4914, ruling B) — "export a single `isRetiredFieldType(t)` diff --git a/ui/packages/fields/src/widgets/BooleanField.tsx b/ui/packages/fields/src/widgets/BooleanField.tsx index 2589138342a..8cca6b29c43 100644 --- a/ui/packages/fields/src/widgets/BooleanField.tsx +++ b/ui/packages/fields/src/widgets/BooleanField.tsx @@ -3,15 +3,19 @@ import { Switch, Checkbox, Label, EmptyValue } from '@object-ui/components'; import { FieldWidgetComponentProps } from './types.js'; import { toDomProps } from './toDomProps.js'; import { useBooleanValueLabel } from './booleanValueLabel.js'; +import { resolveBooleanControl } from './booleanControl.js'; /** - * BooleanField - Toggle input supporting switch and checkbox variants - * Renders as Switch or Checkbox based on field widget configuration + * BooleanField - the two-state input for the `boolean` and `toggle` types. + * Which control it draws is {@link resolveBooleanControl}'s answer: `boolean` + * a checkbox, `toggle` a switch, an explicit boolean `widget` over either. */ export function BooleanField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps) { const config = field as any; - // Use simple type assertion for arbitrary custom properties not in BaseFieldMetadata - const widget = config?.widget; + // The one type-to-widget map the Studio canvas reads too (objectstack#27519). + // This used to draw a switch unless `widget === 'checkbox'`, so a field + // authored as `boolean` ("shown as a checkbox") drew the `toggle` face. + const control = resolveBooleanControl(config); // Generate unique ID using React's useId hook - must be before early returns (rules of hooks) const generatedId = useId(); // Before the readonly early return for the same reason: the hook count must @@ -110,7 +114,7 @@ export function BooleanField({ value, onChange, field, readonly, error, ...props * `"false"` so a valid field says so rather than staying mute. MARKING only: * the message TEXT stays with the host. */ - if (widget === 'checkbox') { + if (control === 'checkbox') { return (
> = { + checkbox: 'checkbox', + boolean: 'checkbox', + switch: 'switch', + toggle: 'switch', +}; + +function faceOf(name: unknown): BooleanControl | undefined { + if (typeof name !== 'string') return undefined; + return Object.prototype.hasOwnProperty.call(BOOLEAN_FACES, name) ? BOOLEAN_FACES[name] : undefined; +} + +export function resolveBooleanControl( + field: { type?: unknown; widget?: unknown } | null | undefined, +): BooleanControl { + return faceOf(field?.widget) ?? faceOf(field?.type) ?? 'checkbox'; +} From b99b0e94c2f011a757ed3a40443f70cbb2439269 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 14:28:47 +0000 Subject: [PATCH 2/4] test(fields): pin the boolean/toggle faces on the form, inline edit and canvas; changeset Claude-Session: https://claude.ai/code/session_01Utp6CY2n1JmZZKrHgtp9jC Co-authored-by: Claude --- .../27519-boolean-checkbox-toggle-switch.md | 13 +++ ...FormDesigner.booleanControl-27519.test.tsx | 51 +++++++++++ .../boolean-label-association-e2e.test.tsx | 55 ++++++----- .../__tests__/booleanControl-27519.test.tsx | 91 +++++++++++++++++++ 4 files changed, 186 insertions(+), 24 deletions(-) create mode 100644 .changeset/27519-boolean-checkbox-toggle-switch.md create mode 100644 ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.booleanControl-27519.test.tsx create mode 100644 ui/packages/fields/src/__tests__/booleanControl-27519.test.tsx diff --git a/.changeset/27519-boolean-checkbox-toggle-switch.md b/.changeset/27519-boolean-checkbox-toggle-switch.md new file mode 100644 index 00000000000..78da140fc3c --- /dev/null +++ b/.changeset/27519-boolean-checkbox-toggle-switch.md @@ -0,0 +1,13 @@ +--- +'@object-ui/fields': patch +'@object-ui/app-shell': patch +--- + +fix(fields): a `boolean` field draws a checkbox and a `toggle` field a switch, in the record form, the grid's inline editor and the Studio canvas preview + +Clause-②: no +Metadata-protocol: none + +Studio's type picker offers "Checkbox — shown as a checkbox" (`boolean`) and "Toggle — shown as a switch" (`toggle`), but both types reached the one `field:boolean` widget, which drew a switch unless the field carried `widget: 'checkbox'`. A field authored as Checkbox therefore drew a switch on the Studio canvas and in the runtime create form. `resolveBooleanControl` (exported from `@object-ui/fields`) is now the one answer: `boolean` draws a checkbox, `toggle` a switch, and an explicit `widget` of `checkbox` / `boolean` or `switch` / `toggle` overrides the type. `BooleanField` and the canvas's control preview both read it. + +Forms that relied on a `boolean` field drawing a switch now draw a checkbox; declare the field as `toggle`, or set `widget: 'switch'`, to keep the switch. diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.booleanControl-27519.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.booleanControl-27519.test.tsx new file mode 100644 index 00000000000..560e2d6663a --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/ObjectFormDesigner.booleanControl-27519.test.tsx @@ -0,0 +1,51 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#27519 — the form designer's control preview draws the boolean + * face the runtime form draws. + * + * The defect: `FieldControlPreview` was a hand-written switch on the raw type. + * A field authored as Checkbox (`boolean`) drew the switch pill, and a Toggle + * (`toggle`) fell to the empty text box. The preview now reads + * `resolveBooleanControl`, the same answer `BooleanField` reads in the record + * form, so the case below compares the card with that function rather than + * restating the table. + */ + +import '@testing-library/jest-dom/vitest'; +import * as React from 'react'; +import { afterEach, describe, expect, it } from 'vitest'; +import { cleanup, render, screen } from '@testing-library/react'; +import { resolveBooleanControl } from '@object-ui/fields'; +import { ObjectFormDesigner } from './ObjectFormDesigner'; + +afterEach(cleanup); + +const FIELDS = [ + { name: 'urgent', type: 'boolean', label: 'Urgent' }, + { name: 'notify', type: 'toggle', label: 'Notify' }, +]; + +function cardControl(label: string): string | null { + const card = screen.getByText(label).closest('[aria-roledescription], [role="button"], div.flex-col'); + return card?.querySelector('[data-boolean-control]')?.getAttribute('data-boolean-control') ?? null; +} + +describe('the canvas previews a boolean field with the runtime form\'s face (objectstack#27519)', () => { + it('Checkbox (`boolean`) previews a checkbox and Toggle (`toggle`) a switch', () => { + render( + {}} + onSelectField={() => {}} + />, + ); + + expect(cardControl('Urgent')).toBe('checkbox'); + expect(cardControl('Notify')).toBe('switch'); + // The same answer the record form's widget reads, not a canvas copy. + expect(cardControl('Urgent')).toBe(resolveBooleanControl({ type: 'boolean' })); + expect(cardControl('Notify')).toBe(resolveBooleanControl({ type: 'toggle' })); + }); +}); diff --git a/ui/packages/fields/src/__tests__/boolean-label-association-e2e.test.tsx b/ui/packages/fields/src/__tests__/boolean-label-association-e2e.test.tsx index 683dedd4eca..a4323935c81 100644 --- a/ui/packages/fields/src/__tests__/boolean-label-association-e2e.test.tsx +++ b/ui/packages/fields/src/__tests__/boolean-label-association-e2e.test.tsx @@ -90,16 +90,23 @@ function labelTargets(): Array<{ text: string; forId: string; resolves: boolean .filter((l) => l.forId !== ''); } -const switchOf = (name: string): Element => { - const el = document.querySelector(`[data-field="${name}"] [role="switch"]`); - if (!el) throw new Error(`no switch rendered for field "${name}"`); +/** The two-state control a field row drew — a switch or a checkbox. */ +const controlOf = (name: string): Element => { + const el = document.querySelector(`[data-field="${name}"] [role="switch"], [data-field="${name}"] [role="checkbox"]`); + if (!el) throw new Error(`no two-state control rendered for field "${name}"`); return el; }; +// A `toggle`, in the shape `ObjectForm` hands the form: the widget id +// `mapFieldTypeToFormType` resolves (`field:boolean` for both boolean types) +// plus the object's own field metadata, whose `type` decides the face — a +// `toggle` draws a switch, a `boolean` a checkbox (objectstack#27519). The +// two-field case below hosts one of each. const BOOLEAN_FIELD = { name: 'notifications', label: 'Email Notifications', - type: 'boolean', + type: 'field:boolean', + field: { name: 'notifications', label: 'Email Notifications', type: 'toggle' }, }; describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', () => { @@ -127,7 +134,7 @@ describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', // duplicate is pinned by the label-text count below. const labelled = screen.getAllByLabelText('Email Notifications'); expect(labelled).toHaveLength(1); - expect(labelled[0]).toBe(switchOf('notifications')); + expect(labelled[0]).toBe(controlOf('notifications')); expect(labelled[0]).toHaveAttribute('role', 'switch'); }); @@ -142,7 +149,7 @@ describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', it('activating the visible label toggles the switch', () => { renderForm(BOOLEAN_FIELD, false); - const control = switchOf('notifications'); + const control = controlOf('notifications'); expect(control).toHaveAttribute('aria-checked', 'false'); // The user-facing symptom of #3952: the normal affordance for a switch row @@ -150,13 +157,13 @@ describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', // association the form set up. fireEvent.click(screen.getByText('Email Notifications')); - expect(switchOf('notifications')).toHaveAttribute('aria-checked', 'true'); + expect(controlOf('notifications')).toHaveAttribute('aria-checked', 'true'); }); it('the control keeps the HOST id verbatim — the widget does not rename it', () => { renderForm(BOOLEAN_FIELD, false); - const control = switchOf('notifications'); + const control = controlOf('notifications'); const id = control.getAttribute('id') ?? ''; // The host's id is a `useId()`-derived form-item id; the field name is what // the widget used to substitute for it. @@ -185,11 +192,14 @@ describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', ); expect(labelTargets().filter((l) => !l.resolves)).toEqual([]); - // Each label reaches its OWN switch (a shared/colliding id would make both - // resolve to the first one). + // Each label reaches its OWN control (a shared/colliding id would make both + // resolve to the first one). The `boolean` row draws a checkbox, the + // `toggle` row a switch (objectstack#27519). fireEvent.click(screen.getByText('Weekly Digest')); - expect(switchOf('digest')).toHaveAttribute('aria-checked', 'true'); - expect(switchOf('notifications')).toHaveAttribute('aria-checked', 'false'); + expect(controlOf('digest')).toHaveAttribute('role', 'checkbox'); + expect(controlOf('digest')).toHaveAttribute('aria-checked', 'true'); + expect(controlOf('notifications')).toHaveAttribute('role', 'switch'); + expect(controlOf('notifications')).toHaveAttribute('aria-checked', 'false'); }); }); @@ -203,7 +213,7 @@ describe('a STANDALONE boolean widget keeps its own accessible name (objectui#39 {}} - field={{ name: 'notifications', label: 'Email Notifications', type: 'boolean' } as any} + field={{ name: 'notifications', label: 'Email Notifications', type: 'toggle' } as any} />, ); @@ -223,7 +233,6 @@ describe('a STANDALONE boolean widget keeps its own accessible name (objectui#39 name: 'agreed', label: 'I agree', type: 'boolean', - widget: 'checkbox', } as any } />, @@ -259,7 +268,7 @@ describe('a host that labels by field NAME keeps its association (objectui#3952)
, ); - const control = document.querySelector('[role="switch"]')!; + const control = document.querySelector('[role="checkbox"]')!; expect(control).toHaveAttribute('id', 'confirmed'); expect(labelTargets().filter((l) => !l.resolves)).toEqual([]); // The host's OWN label reaches the control through that id. @@ -268,15 +277,13 @@ describe('a host that labels by field NAME keeps its association (objectui#3952) }); describe('a host-supplied id wins for BOTH variants (objectui#3952)', () => { - // The checkbox variant is unreachable through the standalone form renderer — - // `resolvedType = widget || field.widget || type` turns `widget: 'checkbox'` - // into the renderer's own BUILTIN `checkbox` branch before the registry is - // consulted — so its host contract is pinned at the prop boundary, exactly - // as ``'s Slot delivers it. + // Pinned at the prop boundary, exactly as ``'s Slot delivers + // it: a `toggle` draws the switch variant and a `boolean` the checkbox + // variant (objectstack#27519). it.each([ - ['switch', undefined, 'switch'], - ['checkbox', 'checkbox', 'checkbox'], - ] as const)('%s variant uses the id the host handed it', (_name, widget, role) => { + ['switch', 'toggle', 'switch'], + ['checkbox', 'boolean', 'checkbox'], + ] as const)('%s variant uses the id the host handed it', (_name, type, role) => { render( , ); diff --git a/ui/packages/fields/src/__tests__/booleanControl-27519.test.tsx b/ui/packages/fields/src/__tests__/booleanControl-27519.test.tsx new file mode 100644 index 00000000000..52b6b3c4f23 --- /dev/null +++ b/ui/packages/fields/src/__tests__/booleanControl-27519.test.tsx @@ -0,0 +1,91 @@ +/** + * 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. + */ + +/** + * objectstack#27519 — one type-to-widget map for the two boolean types. + * + * Studio's type picker offers "Checkbox — shown as a checkbox" (`boolean`) and + * "Toggle — shown as a switch" (`toggle`). Both resolve to the one + * `field:boolean` widget, which drew a switch unless the field carried + * `widget: 'checkbox'`, so a field authored as Checkbox drew a switch in the + * record form and in the grid's inline editor. `resolveBooleanControl` is the + * one answer every surface reads (the Studio canvas preview included, pinned + * beside `ObjectFormDesigner`); these pin it and the two runtime hosts. + */ +import { describe, it, expect, afterEach } from 'vitest'; +import { render, cleanup } from '@testing-library/react'; +import { resolveBooleanControl } from '../index'; +import { BooleanField } from '../widgets/BooleanField'; +import { FieldEditWidget } from '../FieldEditWidget'; + +afterEach(cleanup); + +describe('resolveBooleanControl', () => { + it.each([ + [{ type: 'boolean' }, 'checkbox'], + [{ type: 'toggle' }, 'switch'], + // The bare widget id of a hand-authored form entry, and no type at all: + // the `boolean` type's own face. + [{ type: 'field:boolean' }, 'checkbox'], + [{}, 'checkbox'], + [undefined, 'checkbox'], + ] as const)('%o draws a %s by its type', (field, control) => { + expect(resolveBooleanControl(field)).toBe(control); + }); + + it.each([ + [{ type: 'boolean', widget: 'switch' }, 'switch'], + [{ type: 'boolean', widget: 'toggle' }, 'switch'], + [{ type: 'toggle', widget: 'checkbox' }, 'checkbox'], + [{ type: 'toggle', widget: 'boolean' }, 'checkbox'], + ] as const)('an explicit boolean widget wins: %o draws a %s', (field, control) => { + expect(resolveBooleanControl(field)).toBe(control); + }); + + it('a widget that names no boolean face leaves the type to answer', () => { + expect(resolveBooleanControl({ type: 'toggle', widget: 'star_rating' })).toBe('switch'); + expect(resolveBooleanControl({ type: 'boolean', widget: '' })).toBe('checkbox'); + }); +}); + +const roleDrawn = (): string | null => { + const el = document.querySelector('[role="switch"], [role="checkbox"]'); + return el?.getAttribute('role') ?? null; +}; + +describe('the record form widget and the inline editor draw the same face', () => { + it.each([ + ['boolean', undefined, 'checkbox'], + ['toggle', undefined, 'switch'], + ['boolean', 'switch', 'switch'], + ['toggle', 'checkbox', 'checkbox'], + ] as const)('BooleanField: type %s, widget %s draws a %s', (type, widget, role) => { + render( + {}} + field={{ name: 'urgent', label: 'Urgent', type, widget } as any} + />, + ); + expect(roleDrawn()).toBe(role); + }); + + it.each([ + ['boolean', 'checkbox'], + ['toggle', 'switch'], + ] as const)('FieldEditWidget: type %s draws a %s', (type, role) => { + render( + {}} + field={{ name: 'urgent', label: 'Urgent', type } as any} + />, + ); + expect(roleDrawn()).toBe(role); + }); +}); From 11dd9ecd8abd2aedf42a9c73322e8104d5f3017d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 14:49:23 +0000 Subject: [PATCH 3/4] test: boolean rows draw a checkbox, toggle rows a switch, in the form, inline edit and dialogs Claude-Session: https://claude.ai/code/session_01Utp6CY2n1JmZZKrHgtp9jC Co-authored-by: Claude --- .../formPageRequiredMarker-10178.test.tsx | 6 ++--- .../FormPage.sharedWidgets-10179.test.tsx | 12 +++++----- .../fields/src/standard-widgets.test.tsx | 22 ++++++++++++++----- .../InlineFieldInput.delegation.test.tsx | 5 +++-- ...FieldsDialog.ariaInvalidText-7126.test.tsx | 14 +++++++----- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/ui/apps/console/src/__tests__/formPageRequiredMarker-10178.test.tsx b/ui/apps/console/src/__tests__/formPageRequiredMarker-10178.test.tsx index 4fd5797b7bc..6d6cd139cd2 100644 --- a/ui/apps/console/src/__tests__/formPageRequiredMarker-10178.test.tsx +++ b/ui/apps/console/src/__tests__/formPageRequiredMarker-10178.test.tsx @@ -133,10 +133,10 @@ describe('objectui#10178 — FormPage keeps the required `*` out of the accessib it('a required checkbox has no `*` in its name and announces required via aria-required', async () => { await renderForm(); // Since objectui#10179 a `boolean` row renders the shared `BooleanField` - // (a switch), and the row's `