Interactive component machines
Interactive component machines are framework-neutral behavior models for accessible UI parts. They turn user input and external changes into state, focus movement, selection updates, overlay behavior, and DOM-facing results that any supported framework can render.
Product model
Machine catalog
The catalog covers common controls and higher-level interaction patterns. Each machine owns the behavior for one component family while its framework adapter supplies the way that behavior reaches the view.
| Family | Component machines | Primary user need |
|---|---|---|
| Selection and navigation | Accordion, carousel, cascade select, combobox, listbox, menu, navigation menu, pagination, radio group, rating group, select, steps, tabs, toggle group, tree view, table of contents | Move through choices or sections and keep the active choice clear |
| Overlay and disclosure | Collapsible, dialog, drawer, floating panel, hover card, popover, toast, tooltip, tour | Show, hide, layer, or dismiss content without losing context |
| Form and input | Angle slider, checkbox, color picker, date input, date picker, editable, file upload, number input, password input, pin input, signature pad, slider, switch, tags input, toggle | Enter, change, validate, or submit a value |
| Specialized interaction | Async list, avatar, clipboard, image cropper, marquee, presence, progress, QR code, scroll area, splitter, timer | Support a focused interaction that does not fit the main control groups |
The family pages describe the user-facing behavior in each group: selection and navigation machines, overlay and disclosure machines, form and input machines, and specialized interaction machines.
References: packages/…/accordion.machine.ts• L8-23 packages/…/select.machine.ts• L22-37 packages/…/dialog.machine.ts• L10-30 packages/…/date-picker.machine.ts• L66-149
Shared interaction model
Each machine describes a small state model. An event such as a click, key press, focus change, or outside interaction is matched to a transition. The transition can change state or run an action, while guards choose the valid path when behavior depends on props or current state.
The machine keeps changing values in context. Context is the reactive data that represents choices, focus, open status, input text, or other component state. Props provide configuration and can make a value controlled by an outside owner. Computed values describe facts derived from props and context. Refs hold short-lived values that do not need to drive rendering.
The model below shows how an interaction becomes a rendered result. The service is the live machine instance exposed to a framework adapter.
flowchart LR
A[User or external event] --> B[Machine transition]
B --> C{Guard}
C -->|allowed| D[State and context update]
C -->|blocked| E[No state change]
D --> F[Actions and effects]
F --> G[Framework service]
G --> H[Props and DOM behavior]
This shared model lets a selection control and a modal use the same kind of event-to-state flow even though their user goals differ. The component-specific rules remain in the machine, while the public service gives renderers a common way to read state and send events.
References: packages/…/types.ts• L99-119 packages/…/types.ts• L196-241 packages/…/accordion.machine.ts• L46-91 packages/…/dialog.machine.ts• L57-121
Framework-neutral boundary
The machine does not render markup. It returns a service with state, context access, computed values, refs, a DOM scope, and send for events. A connector maps that service to the roles, properties, event handlers, and IDs required by a component view.
The same machine contract runs through adapters for React, Vue, Solid, Svelte, Preact, or vanilla use. The adapter supplies the host framework's reactive update rules, but it preserves the machine's state transitions and service shape. Framework integrations explains this boundary in more detail, while machine authoring explains how to add or change a machine.
References: packages/…/types.ts• L269-285 packages/…/machine.ts• L46-54 packages/…/machine.ts• L343-355 packages/…/machine.ts• L37-40 packages/…/machine.ts• L30-37
Interaction architecture
State and value ownership
Machines separate transient interaction state from values that an application may own. Focused item, highlighted item, open status, hover state, and active input section are examples of transient state. A selected value or entered date can use a default value for local use or a controlled value with a change callback.
This split gives the catalog a stable contract. The machine handles keyboard and pointer behavior in both modes, while the application decides whether it accepts each proposed value. Selection machines show this pattern clearly: accordion tracks focused and expanded values, and select tracks value, highlighted value, and selected item data.
References: packages/…/types.ts• L34-65 packages/…/accordion.machine.ts• L23-39 packages/…/select.machine.ts• L39-102
Focus and DOM scope
Focus is part of component behavior, not only a view concern. Machines use a scoped DOM interface to find the relevant trigger, item, input, or content element. This keeps focus movement tied to the component instance and also supports a custom root such as a shadow root.
The scope also gives a machine access to the active element, document, and window. Actions use it for work such as roving focus, focus restoration, scrolling, positioning, and form synchronization. The connector still decides the markup and assigns the IDs that make these queries possible.
References: packages/…/types.ts• L78-87 packages/…/tabs.machine.ts• L191-237 packages/…/select.machine.ts• L582-598 packages/…/dialog.machine.ts• L164-195
Effects and cleanup
Effects represent behavior that is active for a state or for the machine lifetime. They can watch outside interaction, trap focus, prevent scroll, observe layout, announce changes, or connect to form state. Each active effect has a cleanup step when its state ends or its machine stops.
This lifecycle is important for accessible behavior. A dialog must release its focus trap and scroll lock. A select must stop its outside-interaction and positioning trackers. A date picker must destroy its live region. Cleanup makes component instances safe to mount, unmount, and remount.
References: packages/…/machine.ts• L167-205 packages/…/machine.ts• L310-331 packages/…/dialog.machine.ts• L57-61 packages/…/select.machine.ts• L326-330 packages/…/date-picker.machine.ts• L241-242
Accessibility behavior
Keyboard and pointer interaction
The catalog treats keyboard input, pointer input, and focus changes as first-class events. A machine can move focus through a set of items, change a highlighted item without changing the value, or delay a value change until activation. This avoids making pointer-only behavior the source of truth.
For example, tabs support automatic or manual activation and directional movement. Select supports typeahead, highlighted-item scrolling, and focus restoration after selection. Date picker maps grid keys to day, month, year, and range movement.
References: packages/…/tabs.machine.ts• L94-157 packages/…/select.machine.ts• L326-425 packages/…/date-picker.machine.ts• L420-714
Overlay containment
Overlay machines coordinate visibility with the boundary around the overlay. They can react to Escape, outside focus, outside pointer input, and dismissal requests. Modal behavior adds focus trapping, background hiding, and body scroll prevention. Non-modal behavior can keep the page interactive while still restoring focus when needed.
The overlay state is also compatible with controlled use. In that mode, an event calls the open or close callback and the application supplies the resulting open value. This keeps the machine and the application aligned without making the overlay assume ownership of external state.
References: packages/…/dialog.machine.ts• L10-25 packages/…/dialog.machine.ts• L128-203 packages/…/dialog.machine.ts• L205-245 packages/…/select.machine.ts• L463-494
Announcements and native form behavior
Some interactions need more than visible focus. Machines can announce a value or range through a live region, preserve native form events through a hidden control, and expose state through the attributes produced by the connector.
Date picker announces selected dates and visible ranges. Select keeps its hidden select element aligned with the machine value and dispatches a change event. These paths connect rich custom interaction to assistive technology and existing form systems.
References: packages/…/date-picker.machine.ts• L768-841 packages/…/select.machine.ts• L731-743 packages/…/select.machine.ts• L775-782
Interaction flows
Selection flow
Selection machines maintain a distinction between what is focused or highlighted and what is selected. Navigation changes the current item. Activation changes the value. The machine then reports the value through its change contract and updates any derived item data.
This distinction supports single and multiple selection, typeahead, looped navigation, controlled values, and collections that change over time. Read selection and navigation machines for the family-level map.
References: packages/…/accordion.machine.ts• L52-91 packages/…/select.machine.ts• L147-169 packages/…/select.machine.ts• L600-669
Disclosure flow
Disclosure machines move between visible and hidden states while preserving the relationship between a trigger and its content. Overlay variants add a dismissal boundary and focus policy. The usual flow is: an event requests open or close, guards account for controlled use, state entry starts the required effects, and exit runs cleanup and focus restoration.
The family includes simple disclosure such as collapsible content and layered content such as dialogs, popovers, and drawers. Read overlay and disclosure machines for their differences.
References: packages/…/dialog.machine.ts• L57-121 packages/…/dialog.machine.ts• L227-245 packages/…/select.machine.ts• L173-211 packages/…/select.machine.ts• L326-356
Input flow
Input machines turn text, pointer, keyboard, and form events into normalized values. They keep editing state separate from committed value when needed, then report changes through the component's public callbacks. Constraints such as ranges, selection modes, and disabled state guide which transitions are allowed.
Date picker shows the broader pattern: it accepts typed text and calendar input, parses and constrains dates, maintains a focused date, and supports single, range, or multiple selection. Read form and input machines for the input family.
References: packages/…/date-picker.machine.ts• L158-239 packages/…/date-picker.machine.ts• L278-357 packages/…/date-picker.machine.ts• L1181-1221
Change checklist
When these files or sections are changed, remember to consider these:
- When a machine changes an event or state name, update the connector that maps that state to DOM properties and event handlers.
- When a controlled value or callback changes, check the matching bindable context and every framework service that delivers prop updates.
- When a focus or dismissal rule changes, check the related scope queries, exclusion elements, and focus restoration path.
- When a collection or item identity changes, check highlighted-item state, selected-item derivation, and scroll or typeahead behavior together.
- When an effect is added to a state, define its cleanup and check both state exit and machine unmount paths.
- When a machine is added to a family, update the catalog and the matching family page without changing the shared service contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A controlled open or value prop changes without the owning callback updating it | The machine can request a transition but the visible state remains controlled by the old value | Treat controlled callbacks as a state handoff and update the prop from the callback result |
| A connector gives a machine the wrong IDs or root scope | Focus, dismissal, positioning, or form synchronization targets the wrong element or does nothing | Keep the connector's IDs and getRootNode aligned with the machine's scope queries |
| A state effect does not return or run cleanup | Listeners, focus traps, scroll locks, observers, or live regions can remain after the component leaves the state | Pair every long-lived effect with cleanup and verify state exit plus unmount behavior |
| A selection collection changes without resynchronizing selected or highlighted items | The displayed item, active descendant, and reported value can disagree | Re-derive item state when the collection or selected values change |
| An event has no transition for the current state | The interaction is ignored without changing state or running its action | Add the event to each state that can receive it, or make the unsupported path explicit |
Key files
| File | Why to read it |
|---|---|
| packages/…/types.ts | Defines the shared machine, service, context, scope, transition, and lifecycle contracts. |
| packages/…/create-machine.ts | Shows the small core API used to create typed machines and compose guards. |
| packages/…/machine.ts | Shows the framework-neutral runtime flow from events to state, actions, effects, and subscriptions. |
| packages/…/machine.ts | Shows how the same service contract is connected to React reactivity and lifecycle. |
| packages/…/machine.ts | Shows how the service contract handles Vue refs, mount timing, and buffered events. |
| packages/…/accordion.machine.ts | A compact example of focus, single or multiple selection, guards, and value callbacks. |
| packages/…/tabs.machine.ts | Illustrates navigation, activation modes, focus movement, and derived indicator state. |
| packages/…/select.machine.ts | Illustrates collection-backed selection, typeahead, controlled open state, dismissal, positioning, and form sync. |
| packages/…/dialog.machine.ts | Illustrates modal policy, focus containment, outside dismissal, background hiding, and cleanup. |
| packages/…/date-picker.machine.ts | Illustrates a large input machine with parsing, keyboard navigation, range selection, announcements, and overlay behavior. |