Choice1 check

FormSwitch

On or off for a setting.

Example

Every Monday at 8:00

Installation
bunx --bun shadcn@latest add @fieldkit/form-switch

Needs the @fieldkit registry. Add it once

Usage
  1. 1

    Add the field to your schema

    schema.ts
    import { z } from "zod"
    export const schema = z.object({  notifications: z.boolean(),})
  2. 2

    Render it inside a Form

    The name prop matches the schema key.

    example-form.tsx
    import { Form } from "@/components/form/form"import { FormSwitch } from "@/components/form/form-switch"import { FormSubmit } from "@/components/form/form-submit"import { FieldGroup } from "@/components/ui/field"import { schema } from "./schema"
    export function ExampleForm() {  return (    <Form      schema={schema}      defaultValues={{ notifications: false }}      onSubmit={save}    >      <FieldGroup>        <FormSwitch name="notifications" />        <FormSubmit>Save</FormSubmit>      </FieldGroup>    </Form>  )}
Checks
True or falsez.boolean()None
Best practices
  • Use for settings, not consent
Try these values
Terminal
z.boolean()
InputResultOutput
trueValidtrue
falseValidfalse
API reference

FormSwitch

labelReact.ReactNodeDefaults to the label from the name.

Field frame

namestringKey in the schema. Also picks the preset label and autocomplete.
labelReact.ReactNodeOverrides the preset label. Pass null to hide it.
descriptionReact.ReactNodeHint under the control.
requiredbooleanOverrides the asterisk read from the schema.
fieldPropsFormFieldPropsProps for the wrapping Field, such as className.

Search docs

Find a component, input or example