Browse docs
Browse docs
Toggle switch with optional label and helper text. Integrates with DashForm automatically — value is stored as a boolean, identical to Checkbox but with a different visual control.
Form-connected checkbox input built on top of Material-UI.
Switch integrates automatically with DashForm and the Dashforge form engine. Registration, validation, error handling, reactive visibility, and RBAC orchestration are handled internally by the component.
The component is designed for form-driven workflows rather than standalone state orchestration.
The name prop is required to connect the field to the form schema and the internal form engine.
<Switch
name="notifications"
label="Enable email notifications"
defaultChecked
/>A switch bound to the form by name. The form stores a boolean.
<Switch name="notifications" label="Enable notifications" />defaultChecked sets the initial value.
<Switch name="darkMode" label="Dark mode" defaultChecked />Error state with helper text.
<Switch name="agree" label="I agree" error helperText="This field is required" />| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | Field name. Required. |
label | string | — | Label text displayed next to the switch. |
defaultChecked | boolean | false | Initial on/off state (uncontrolled). |
disabled | boolean | false | Disables the switch. |
error | boolean | false | Error visual state. |
helperText | string | — | Hint or error text below the switch. |
access | AccessRequirement | — | RBAC access requirement. Controls visibility, disabled, and readonly state based on role permissions. |
rules | RegisterOptions | — | React Hook Form validation rules. |
visibleWhen | VisibleWhenCondition | — | Conditional visibility expression. |
true = on, false = off).Switch supports progressive adoption — use it as a standalone controlled input, integrate with React Hook Form, or conditionally show it based on other form state.
Available Now
Switch works as a standard React controlled component with familiar patterns. No proprietary lock-in required.
<Switch
checked={isEnabled}
onChange={(e) => setIsEnabled(e.target.checked)}
label="Enable notifications"
/>Integration-Friendly
Designed to integrate with React Hook Form workflows through DashForm. Compatible with existing form-library patterns.
<DashForm>
<Switch
name="notifications"
label="Email notifications"
rules={{ required: 'Please enable or disable' }}
/>
</DashForm>Switch can participate in engine-driven visibility rules through visibleWhen. Use it when a toggle depends on other form state.
<Switch
name="marketingEmails"
label="Send marketing emails"
visibleWhen={(engine) =>
engine.getNode('emailsEnabled')?.value === true
}
/>Declarative role-based access control via the access prop. The component calls useAccessState(access) internally and maps the resolved permission to one of three field states — no if statements or manual checks needed in the parent.
The access prop accepts an AccessRequirement object:
| Field | Type | Description |
|---|---|---|
resource | string | The resource being protected (e.g. 'employee', 'invoice'). |
action | string | The action being checked (e.g. 'read', 'update', 'delete'). |
onUnauthorized | 'hide' | 'disable' | 'readonly' | What to render when the user lacks permission. Defaults to 'hide'. |