Reference headless
switchAttachment
# CreateSwitchOptions
Members
disabled?optional disabled?: booleanConstruct the machine in the disabled state. Defaults to
false.###### Inherited from
CreateSwitchInput.disabledid?optional id?: stringinitial?optional initial?: booleanInitial checked value. Defaults to
false.###### Inherited from
CreateSwitchInput.initialonCheckedChange?optional onCheckedChange?: (checked) => voidCalled whenever the checked value changes via user interaction. Not called for controlled
set()updates that came from the parent.###### Parameters
###### checked
boolean###### Returns
void
# SwitchContext
Members
checkedchecked: booleanWhether the switch is currently on. Mirrored as
aria-checked.togglestoggles: numberNumber of user-initiated toggles since construction.
# SwitchController
Members
checkedreadonly checked: booleancontextreadonly context: Readonly<SwitchContext>disabledreadonly disabled: booleanidreadonly id: stringmachinereadonly machine: SwitchMachinerootreadonly root: Attachmentstatereadonly state: SwitchStateset()set(checked): void###### Parameters
###### checked
boolean###### Returns
voidsetDisabled()setDisabled(disabled): void###### Parameters
###### disabled
boolean###### Returns
voidsubscribe()subscribe(listener): () => void###### Parameters
###### listener
(
snapshot) =>void###### Returns
() =>
voidtoggle()toggle(): void###### Returns
void
# Attachment
Attachment = (node) => void | (() => void)Parameters
nodeHTMLElement
Returns
void | (() => void)# SwitchEvent
SwitchEvent = { type: "TOGGLE"; } | { checked: boolean; type: "SET"; } | { type: "DISABLE"; } | { type: "ENABLE"; }All events the Switch machine can receive.
# SwitchMachine
SwitchMachine = Machine<SwitchContext, SwitchEvent, SwitchState># SwitchState
SwitchState = "off" | "on" | "disabled"# createSwitch ( )
createSwitch(options?): SwitchControllerCreate a Switch controller plus its {@attach}-compatible root attachment.
Parameters
options?CreateSwitchOptions = {}
Returns
SwitchController