Display & Navigation · Switchstable
Switch
Turns a single setting on or off with immediate effect, with an optional label and description (Switch Field).
Preview
#previewSwitch size, value, layout and state. Show code opens the React and CSS below.
medium · on · field · default
switch-example.tsx
import { Switch } from "@blade-ai/weft/components/switch";
export function AlertsSetting({ isOn, onChange }: Props) {
return (
<Switch
label="Email alerts"
description="Get an email when a payout fails."
isChecked={isOn}
onChange={onChange}
/>
);
}All states
#all-statesEvery size, value and state of the track, plus the Switch Field layout.
Off
On
Hover · off
Hover · on
Focus · off
Focus · on
Disabled · off
Disabled · on
Small · off
Small · on
Small · hover
Small · disabled
Field · on
Field · off
Field · disabled
Props
#propsBooleans are is-prefixed. Without a visible label, accessibilityLabel is required. Native button attributes pass through.
Prop
Type
Default
Description
label
string
—
Visible label. Renders the Switch Field layout: label and description on the left, track on the right.
description
string
—
Helper text under the label.
accessibilityLabel
string
—
Accessible name when there is no visible label. Becomes aria-label.
isChecked
boolean
—
Controlled on/off value. Use with onChange.
isDefaultChecked
boolean
false
Initial value when uncontrolled. Ignored if isChecked is set.
size
"small" | "medium"
"medium"
Track 24x14 (small) or 32x18 (medium).
isDisabled
boolean
false
Native disabled: not focusable, 60% opacity.
onChange
(isChecked: boolean) => void
—
Fires on click, Space and Enter with the next value. Not fired while disabled.
name
string
—
Form field name. Renders a hidden input so the value submits with a form.
value
string
"on"
Value submitted when on.
testID
string
—
Rendered as data-testid.
data-state
"hover" | "focus"
—
Docs and testing hook: forces a visual state without interaction.
Usage
#usageShort rules for choosing and writing switches.
Do
Use a switch for settings that apply immediately, with no Save step.
Label the setting itself ("Email alerts"), not the action.
Add a description when the effect is not obvious.
Pick the small size inside dense lists and tables.
Don't
Do not use a switch inside a form that needs a Submit; use a checkbox.
Do not use it to pick between two named options; use a radio group.
Do not change the label text when the value flips.
Do not leave it without an accessible name.
Accessibility
#accessibilityA native button with role switch. Space and Enter both toggle.
Keyboard
Key
Action
Tab
Moves focus to the switch.
Space
Toggles the switch.
Enter
Toggles the switch.
ARIA
Element
Role / attribute
When
Track
role="switch" · aria-checked
Always. Reflects the current value.
Track
aria-labelledby · aria-label
Visible label wins; otherwise accessibilityLabel.
Track
aria-describedby
When a description is set.
Hidden input
name · value
When name is set, so the value submits with a form.