Switch API

API documentation for Switch component

Switch#

Props#

Defines valid properties in Switch component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: SwitchInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: SwitchInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<SwitchPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: SwitchInstance) => ReactNode)
null
The children to render.
valueunknown
null
Value of the switch.
disabledboolean
false
When present, it specifies that the element should be disabled.
requiredboolean
false
When present, it specifies that the element is required.
invalidboolean
false
When present, it specifies that the component should have invalid state style.
inputIdstring
null
Identifier of the underlying input element.
inputStyleCSSProperties
null
Inline style of the input field.
inputClassNamestring
null
Style class of the input field.
ariaLabelstring
null
Establishes a string value that labels the component.
ariaLabelledbystring
null
Establishes relationships between the component and label(s) where its value should be one or more element IDs.
onFocus(event: FocusEvent<HTMLInputElement>) => void
null
Callback function that is called when the switch is focused.
onBlur(event: FocusEvent<HTMLInputElement>) => void
null
Callback function that is called when the switch loses focus.
onCheckedChange(event: SwitchChangeEvent) => void
null
Callback fired when the switch's checked state changes.
checkedboolean
null
When present, it specifies the input's checked state.
defaultCheckedboolean
null
The default value for the input when not controlled by `checked` and `onCheckedChange` .
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

State#

Defines valid state in Switch component.

nametypedefaultdescription
checkedboolean
null
The checked state of the useSwitch.

Exposes#

Defines the methods and properties exposed by Switch component.

nametypedefaultdescription
stateuseSwitchState
null
The state of the useSwitch.
onChange(event: useSwitchChangeEvent) => void
null
Callback fired when the useSwitch's checked state changes.

Events#

Event fired when the switch's checked state changes.

nametypedescription
valueunknownValue of the switch.
originalEventChangeEventThe original event that triggered the change.
checkedbooleanThe checked state of the switch.

Interfaces#

Defines passthrough(pt) options of Switch component.

nametypedefaultdescription
rootSwitchPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the root's DOM element.
inputSwitchPassThroughType<HTMLAttributes<HTMLElement>>
null
Used to pass attributes to the input's DOM element.
controlSwitchPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the control's DOM element.
thumbSwitchPassThroughType<HTMLAttributes<HTMLSpanElement>>
null
Used to pass attributes to the thumb's DOM element.

Types#

Instance of Switch component.

values
ComponentInstance<SwitchProps, SwitchState, SwitchExposes>

SwitchControl#

Props#

Defines valid properties in SwitchControl component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: SwitchControlInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: SwitchControlInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<SwitchControlPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: SwitchControlInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by SwitchControl component.

nametypedefaultdescription
switchSwitchInstance
null
The Switch component instance.

Interfaces#

Defines passthrough(pt) options of SwitchControl component.

nametypedefaultdescription
rootSwitchControlPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of SwitchControl component.

values
ComponentInstance<SwitchControlProps, SwitchControlState, SwitchControlExposes>

SwitchThumb#

Props#

Defines valid properties in SwitchThumb component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: SwitchThumbInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: SwitchThumbInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<SwitchThumbPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: SwitchThumbInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by SwitchThumb component.

nametypedefaultdescription
switchSwitchInstance
null
The Switch component instance.

Interfaces#

Defines passthrough(pt) options of SwitchThumb component.

nametypedefaultdescription
rootSwitchThumbPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of SwitchThumb component.

values
ComponentInstance<SwitchThumbProps, SwitchThumbState, SwitchThumbExposes>

useSwitch#

Props#

Defines valid properties in useSwitch.

nametypedefaultdescription
checkedboolean
null
When present, it specifies the input's checked state.
defaultCheckedboolean
null
The default value for the input when not controlled by `checked` and `onCheckedChange` .
onCheckedChange(event: useSwitchChangeEvent) => void
null
Callback fired when the switch's checked state changes.

State#

Defines valid state in useSwitch.

nametypedefaultdescription
checkedboolean
null
The checked state of the useSwitch.

Exposes#

Defines the methods and properties exposed by useSwitch.

nametypedefaultdescription
stateuseSwitchState
null
The state of the useSwitch.
onChange(event: useSwitchChangeEvent) => void
null
Callback fired when the useSwitch's checked state changes.

Events#

Event fired when the switch's checked state changes.

nametypedescription
originalEventEThe original event that triggered the change.
checkedbooleanThe checked state of the switch.

Types#

Instance of useSwitch headless.

values
HeadlessInstance<useSwitchProps, useSwitchState, useSwitchExposes>