FormComponentsSwitch Field

Switch Field

SwitchField is a specialized reusable input component for Shaddy Form.

SwitchField is a reusable switch/toggle component for Shaddy Form. It supports labels, required state, disabled state, flexible layout options, and more. Use it inside a Shaddy Form to collect boolean user input with validation.

Installation

pnpm dlx shadcn@latest add https://shaddy-docs.vercel.app/r/switch-field

Props

NameTypeDefaultDescription
namestring (from react-hook-form Path)requiredThe field name (must match your form schema).
labelstringThe label displayed next to the switch.
classNamestringAdditional CSS classes for the field container.
disabledbooleanfalseDisables the switch when true.
requiredbooleanfalseMarks the field as required.
columnbooleanfalseArranges the switch and label in a column layout.
longGapbooleanfalseAdds extra space between the switch and label.
reversebooleanfalseReverses the order of the switch and label.
gap'2' | '4' | '6' | '8''2'Sets the gap between the switch and label.

Usage

<ShaddyForm>
  <SwitchField name="isActive" label="Active" required gap="4" column />
</ShaddyForm>

Notes

  • You can control the layout and spacing using the column, longGap, reverse, and gap props.