Skip to content

CheckboxEditor

Edits a checkbox field with the shadcn switch.

Terminal window
pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/checkbox-editor.json
Terminal window
pnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/checkbox-editor.json
CheckboxEditor: two states, and the two blocked ones

React

Loading the React demo…

Svelte

Loading the Svelte demo…

done emitted
switch on true
switch off false

There is no third state, and no way to clear the field.

proptypedefaultmeaning
errorMessage(message: string) => ReactNode / Snippet<[string]>—Draws the line under the control.
valuebooleanfalseThe stored boolean. Two-way in Svelte.
onValueChange(value: boolean) => void—Called on every change.
fieldPick<FieldSchema, 'displayName' | 'mandatory'> | nullnullSupplies the accessible label.
labels{ on: string; off: string }{ on: 'Yes', off: 'No' }The word shown beside the switch.
size'sm' | 'md' | 'lg''md'Row height.
disabledbooleanfalse
readonlybooleanfalseKeeps full contrast and refuses the change.
invalidbooleanfalse
errorstring | nullnullA message from the caller.
placeholderstring—Used as the accessible label when there is no field.
class / classNamestring—Merged after the widget's own classes.
eventpayloadwhen
onErrorChangestring | nullThe message changed.

onValueChange fires as soon as the switch moves. There is nothing to commit. onErrorChange fires with null on that same change, so a message the caller set clears when the field is answered.

errorMessage receives the message and renders it.

keydoes
SpaceToggles the switch.
TabMoves off the control.

A checkbox is two-state and never null: a row that was never touched already reads false, a written null is a 400, and false is the only off state (field_types/checkbox).