GitHub

Reference headless

switchAttachment

interface 3 type 4 function 1
interface Interfaces 3

# CreateSwitchOptions

Members

disabled?
optional disabled?: boolean

Construct the machine in the disabled state. Defaults to false.

###### Inherited from

CreateSwitchInput.disabled

id?
optional id?: string
initial?
optional initial?: boolean

Initial checked value. Defaults to false.

###### Inherited from

CreateSwitchInput.initial

onCheckedChange?
optional onCheckedChange?: (checked) => void

Called whenever the checked value changes via user interaction. Not called for controlled set() updates that came from the parent.

###### Parameters

###### checked

boolean

###### Returns

void

interface

# SwitchContext

Members

checked
checked: boolean

Whether the switch is currently on. Mirrored as aria-checked.

toggles
toggles: number

Number of user-initiated toggles since construction.

# SwitchController

Members

checked
readonly checked: boolean
context
readonly context: Readonly<SwitchContext>
disabled
readonly disabled: boolean
id
readonly id: string
machine
readonly machine: SwitchMachine
root
readonly root: Attachment
state
readonly state: SwitchState
set()
set(checked): void

###### Parameters

###### checked

boolean

###### Returns

void

setDisabled()
setDisabled(disabled): void

###### Parameters

###### disabled

boolean

###### Returns

void

subscribe()
subscribe(listener): () => void

###### Parameters

###### listener

(snapshot) => void

###### Returns

() => void

toggle()
toggle(): void

###### Returns

void

type Type Aliases 4

# Attachment

Attachment = (node) => void | (() => void)

Parameters

node
HTMLElement

Returns

void | (() => void)
type

# SwitchEvent

SwitchEvent = { type: "TOGGLE"; } | { checked: boolean; type: "SET"; } | { type: "DISABLE"; } | { type: "ENABLE"; }

All events the Switch machine can receive.

type

# SwitchState

SwitchState = "off" | "on" | "disabled"
function Functions 1

# createSwitch ( )

createSwitch(options?): SwitchController

Create a Switch controller plus its {@attach}-compatible root attachment.

Parameters

options?
CreateSwitchOptions = {}

Returns

SwitchController