Toggle
Toggle is a control that switches between on and off states. Toggle is commonly used for boolean settings and preferences.
Toggle is a control that switches between on and off states. Toggle is commonly used for boolean settings and preferences.
Examples
Basic Usage
Preview unavailable for this example in the static docs build.
Show code
const ToggleDemo = () => {
const [isOn, setIsOn] = useState(false)
return (
<VStack spacing={16}>
<Text>Toggle is {isOn ? 'on' : 'off'}</Text>
<Toggle isOn={isOn} onChange={setIsOn} />
<Toggle isOn={true} onChange={() => {}} />
<Toggle isOn={false} onChange={() => {}} disabled />
</VStack>
)
}API
| Prop | Type | Required | Description |
|---|---|---|---|
isOn | boolean | Yes | Whether the toggle is currently on. |
onChange | (value: boolean) => void | Yes | Callback fired when the toggle state changes. |
disabled | boolean | No | Whether the toggle is disabled. Default: false |
Inherits additional props from Omit<
IBaseElementComponent<'input'>,
'type' | 'checked' | 'onChange' | 'children'
>.
Overview
Toggle is a control that switches between on and off states. Toggle is commonly used for boolean settings and preferences.
SwiftUI Correspondence: Similar to SwiftUI's Toggle.
Notes
- Toggle requires
isOnandonChangeprops for controlled state - Toggle can be disabled with the
disabledprop - Toggle provides visual feedback for state changes
- Use Toggle for binary choices (on/off, enabled/disabled)
Best Practices
- Clear labels: Provide clear labels that indicate what the toggle controls
- State management: Use controlled state for toggle values
- Accessibility: Ensure toggles are keyboard accessible
- Visual feedback: Toggle provides built-in visual feedback
- Grouping: Group related toggles together for better UX
TimelineView
TimelineView re-renders its content on a fixed cadence, matching SwiftUI's scheduled-update mental model with a simple interval-based web adaptation.
Toolbar
Toolbar is a view that displays toolbar items. Toolbar provides a consistent way to display actions and controls, typically at the bottom of the screen.