Switch
A control that allows the user to toggle between checked and not checked.
Features
- Can be controlled or uncontrolled.
- Full keyboard navigation.
Anatomy
API Reference
Root
RdxSwitchRootDirective
Contains all the parts of a switch. An input
will also render when used within a form
to ensure events propagate correctly.
Prop | Default | Type |
---|---|---|
required | — | InputSignalWithTransform<boolean, BooleanInput> When true, indicates that the user must check the switch before the owning form can be submitted. |
ariaLabelledBy | — | InputSignal<undefined | string> Establishes relationships between the component and label(s) where its value should be one or more element IDs. |
ariaLabel | — | InputSignal<undefined | string> Used to define a string that autocomplete attribute the current element. |
checked | false | ModelSignal<boolean> The controlled state of the switch. Must be used in conjunction with onCheckedChange. |
defaultChecked | — | InputSignalWithTransform<boolean, BooleanInput> The state of the switch when it is initially rendered. Use when you do not need to control its state. |
disabled | — | InputSignalWithTransform<boolean, BooleanInput> When `true` , prevents the user from interacting with the switch. |
Emit | Payload |
---|---|
onCheckedChange |
[value: boolean]
Event handler called when the state of the switch changes. |
Input
RdxSwitchInputDirective
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
Thumb
RdxSwitchThumbDirective
The thumb that is used to visually indicate whether the switch is on or off.
Data Attribute | Value |
---|---|
[data-state] | "open" | "closed" |
[data-disabled] | Present when disabled |
Accessibility
Adheres to the Switch
role requirements .