Skip to content

ToggleSwitchField

ToggleSwitchField provides a Cratis-owned labeled on/off switch bound to a boolean property on a command. It is the switch-styled counterpart of CheckboxField.

import { CommandDialog } from '@cratis/components/CommandDialog';
import { ToggleSwitchField } from '@cratis/components/CommandForm';
<CommandDialog command={UpdateProfile} visible={visible} onCancel={() => setVisible(false)}>
<ToggleSwitchField<UpdateProfile> value={c => c.notificationsEnabled} label="Enable notifications" />
</CommandDialog>
PropTypeDefaultDescription
value(instance: TCommand) => unknownRequired. Accessor that returns the bound property from the command instance. Pass the command type as the generic parameter for full type safety.
labelstringText displayed next to the switch. It is the switch’s accessible name — override it to localize.
classNamestringExtra CSS class forwarded to the underlying ToggleSwitch.
ptcomponent-specific partsCratis-owned HTML attributes for stable parts.
ptOptionsobjectLegacy compatibility prop; ignored.
unstyledbooleanfalseLegacy compatibility prop; ignored.
  • Default value is false.
  • The switch is wrapped in a <label>, so the visible text is its accessible name and clicking the text toggles it.
  • Validation state is reflected through aria-invalid and data-invalid.