Reference headless
toggle
# CreateToggleOptions
Members
disabled?optional disabled?: booleanConstruct the machine in the disabled state. Defaults to
false.###### Inherited from
CreateToggleInput.disabledid?optional id?: stringStable id override. If not provided, an id is generated via
@kumiki/primitives/id(crypto.randomUUIDor a counter fallback).initial?optional initial?: booleanInitial pressed value. Defaults to
false.###### Inherited from
CreateToggleInput.initialonPressedChange?optional onPressedChange?: (pressed) => voidCalled whenever the pressed value changes via user interaction (
TOGGLE). Not called for controlledset()updates that already came from the parent.###### Parameters
###### pressed
boolean###### Returns
void
# ToggleContext
Reactive state surfaced to consumers.
Members
pressedpressed: booleanWhether the toggle is currently pressed. Mirrored as
aria-pressed.togglestoggles: numberNumber of user-initiated toggles since construction. Useful for analytics and for detecting infinite-loop bugs in test fixtures.
# ToggleController
Members
contextreadonly context: Readonly<ToggleContext>disabledreadonly disabled: booleanidreadonly id: stringA stable unique id for this controller.
machinereadonly machine: ToggleMachineUnderlying machine — exposed for advanced use, debugging, and tests.
pressedreadonly pressed: booleanrootreadonly root: AttachmentThe Svelte 5 attachment to spread on the toggle's button element.
statereadonly state: ToggleStateset()set(pressed): void###### Parameters
###### pressed
boolean###### Returns
voidsetDisabled()setDisabled(disabled): void###### Parameters
###### disabled
boolean###### Returns
voidsubscribe()subscribe(listener): () => voidSubscribe to state changes. Returns an unsubscribe.
###### Parameters
###### listener
(
snapshot) =>void###### Returns
() =>
voidtoggle()toggle(): void###### Returns
void
# Attachment
Attachment = (node) => void | (() => void)Svelte 5 attachment function. Receives the DOM element and returns an optional teardown.
Parameters
nodeHTMLElement
Returns
void | (() => void)# ToggleEvent
ToggleEvent = { type: "TOGGLE"; } | { pressed: boolean; type: "SET"; } | { type: "DISABLE"; } | { type: "ENABLE"; }All events the Toggle machine can receive.
# ToggleMachine
ToggleMachine = Machine<ToggleContext, ToggleEvent, ToggleState>A running Toggle machine instance.
# ToggleState
ToggleState = "unpressed" | "pressed" | "disabled"State names the machine can be in.
# createToggle ( )
createToggle(options?): ToggleControllerCreate a Toggle controller plus its {@attach}-compatible root attachment.
Parameters
options?CreateToggleOptions = {}
Returns
ToggleController