Skip to main content
← Back to Table of Contents

Summary

Modern boolean toggle designed for settings pages and feature flags. Unlike the native Filament toggle, SwitchField supports description text, status badges, and two distinct layouts: a compact row and a bordered card.

Basic usage

Simple row toggle

Bordered card with badge


State & validation

Stored value

The field stores a boolean true or false. New forms start at false unless you set default(true).

Validation rules

Validation runs when the form is submitted. Supported boolean representations are true, false, 1, 0, '1' and '0'; saved values are canonical booleans. A null state is treated as false. Arrays, nested data, arbitrary strings, decimals and other numbers are rejected, including for an optional switch. Use standard Filament/Laravel rules for additional requirements:

Layouts & Positioning

Layout: Row (default)

Label and description on the left, toggle on the right. Best for dense settings lists.

Layout: Card

Adds a border and padding around the entire field. Ideal for highlighting important options.

Label position

labelPosition() sets the position of the label. start keeps the label first and the switch last; end places the switch before the label. Positions follow the document reading direction in RTL layouts.

Capsule motion and keyboard

Press and hold the switch: its capsule stretches toward the destination while its outer edge remains anchored. Releasing toggles the state and lets the capsule travel on a spring. A keyboard or assistive click without a held press adds a brief stretch pulse. Animation adapts to sm, md and lg, including inline and card layouts.
  • Space: hold to stretch; release to toggle.
  • Enter: toggle the focused switch. Repeated keydown events do not repeatedly toggle it.
  • Tab: move between available switches; disabled switches are skipped.
  • Leaving the button, pointer cancellation, blur or a changed external state clears the held appearance.
  • With reduced motion enabled, the capsule moves immediately; stretch, pulse and ripple effects are disabled.
The whole row or card is clickable. inline() renders only the switch, while inlineWithLabel() places it beside the normal form label:
The default state binding is deferred until the next form request. To update the server after each toggle, enable live():
afterStateUpdated() is a change callback, not a substitute for submission validation. In custom forms, use $this->form->getState() before saving. Disabled fields are not normally included in saved form data. The switch emits bubbling browser input and change events with event.detail.checked after user activation. Pointer gestures, streams or listeners are never shared between instances. No custom animation loop runs while idle.

Configuration API

All methods accept Closure unless noted.

Real-world examples

Terms of Service (Wizard)

Compact Settings List


Playground

/admin/flex-fields/switch See Playground for setup.

CSS classes (reference)

Last modified on October 16, 2026