aihu headless behavior primitives — WAI-ARIA APG patterns as vanilla custom elements, zero CSS.
attachHiddenInputfunction attachHiddenInput(host: HTMLElement, opts: HiddenInputOptions): () => voidAttach a visually-hidden native input to `host`, kept in sync with the provided signals by a single effect.
createCollectionfunction createCollection(): CollectionContextValueThe registration mechanism, usable standalone (roving-focus reuses it).
createDomContextfunction createDomContext<T>(name: string, defaultValue?: T): DomContext<T>Create a context token.
createFocusTrapfunction createFocusTrap(container: Element, options: FocusTrapOptions = {}): FocusTrapdefineButtonfunction defineButton(tag: string): typeof AihuButtonRegister a concrete button tag backed by `AihuButton` (idempotent).
defineCheckboxfunction defineCheckbox(): voidRegister all checkbox custom elements (idempotent; a no-op without a DOM).
defineCollectionfunction defineCollection(tag = 'aihu-collection'): voidRegister `<aihu-collection>` (idempotent; a no-op without a DOM).
defineConfigProviderfunction defineConfigProvider(tag = 'aihu-config-provider'): voidRegister `<aihu-config-provider>` (idempotent; a no-op without a DOM).
defineDialogfunction defineDialog(prefix = 'aihu'): voidRegister all dialog custom elements under `<prefix>-dialog-*` (idempotent per prefix).
defineFormControlfunction defineFormControl(tag = 'aihu-form-control'): voidRegister `<aihu-form-control>` (idempotent; a no-op without a DOM).
defineInputfunction defineInput(tag = 'aihu-input'): voidRegister `<aihu-input>` (idempotent; a no-op without a DOM).
defineLabelfunction defineLabel(tag = 'aihu-label'): voidRegister `<aihu-label>` (idempotent; a no-op without a DOM).
definePopoverfunction definePopover(prefix = 'aihu'): voidRegister all popover custom elements under `<prefix>-popover-*` (idempotent per prefix).
definePresenceGatefunction definePresenceGate(tag = 'aihu-presence-gate'): voidRegister `<aihu-presence-gate>` (idempotent — safe to call repeatedly; a no-op without a DOM).
defineRadioGroupfunction defineRadioGroup(): voidRegister all radio-group custom elements (idempotent; a no-op without a DOM).
defineRovingFocusfunction defineRovingFocus(tag = 'aihu-roving-focus'): voidRegister `<aihu-roving-focus>` (idempotent; a no-op without a DOM).
defineSeparatorfunction defineSeparator(tag = 'aihu-separator'): voidRegister `<aihu-separator>` (idempotent; a no-op without a DOM).
defineSliderfunction defineSlider(): voidRegister all slider custom elements (idempotent; a no-op without a DOM).
defineSwitchfunction defineSwitch(): voidRegister all switch custom elements (idempotent; a no-op without a DOM).
defineTextareafunction defineTextarea(tag = 'aihu-textarea'): voidRegister `<aihu-textarea>` (idempotent; a no-op without a DOM).
defineTooltipfunction defineTooltip(prefix = 'aihu'): voidRegister all tooltip custom elements under `<prefix>-tooltip-*` (idempotent per prefix).
injectContextfunction injectContext<T>(from: Element, ctx: DomContext<T>): T | Read<T>Resolve `ctx` for `from` by walking UP the DOM from `from.parentNode`, crossing `ShadowRoot` boundaries (`ShadowRoot → .host`), nearest-wins.
injectValuefunction injectValue<T>(from: Element, ctx: DomContext<T>): TLike `injectContext`, but for the common case where a context carries a raw (non-signal) value — typically an object whose fields are themselves signals.
provideContextfunction provideContext<T>(host: Element, ctx: DomContext<T>, value: T | Read<T>): voidProvide `value` for `ctx` on `host`.
checkboxContextconst checkboxContextcollectionContextconst collectionContextconfigContextconst configContextdialogContextconst dialogContextformControlContextconst formControlContextHTMLElementBaseconst HTMLElementBase: typeof HTMLElement`HTMLElement` in a DOM; an inert, throw-on-construct placeholder elsewhere.
popoverContextconst popoverContextpresenceContextconst presenceContextContext carrying the gate's `present` signal to descendants.
radioGroupContextconst radioGroupContextradioGroupItemContextconst radioGroupItemContextsliderContextconst sliderContextswitchContextconst switchContexttooltipContextconst tooltipContextAihuButtonclass AihuButton extends HTMLElementBaseAihuCheckboxIndicatorclass AihuCheckboxIndicator extends HTMLElementBasePresentational styling hook: mirrors the root's state, hidden from AT.
AihuCheckboxRootclass AihuCheckboxRoot extends HTMLElementBaseAihuCollectionclass AihuCollection extends HTMLElementBaseAihuConfigProviderclass AihuConfigProvider extends HTMLElementBaseAihuDialogBackdropclass AihuDialogBackdrop extends DialogPieceAihuDialogCloseclass AihuDialogClose extends DialogPieceAihuDialogContentclass AihuDialogContent extends DialogPieceAihuDialogDescriptionclass AihuDialogDescription extends DialogPieceAihuDialogRootclass AihuDialogRoot extends HTMLElementBaseAihuDialogTitleclass AihuDialogTitle extends DialogPieceAihuDialogTriggerclass AihuDialogTrigger extends DialogPieceAihuFormControlclass AihuFormControl extends HTMLElementBaseAihuInputclass AihuInput extends AihuTextControlBaseAihuLabelclass AihuLabel extends HTMLElementBaseAihuPopoverContentclass AihuPopoverContent extends PopoverPieceAihuPopoverRootclass AihuPopoverRoot extends HTMLElementBaseAihuPopoverTriggerclass AihuPopoverTrigger extends PopoverPieceAihuPresenceGateclass AihuPresenceGate extends HTMLElementBaseAihuRadioGroupIndicatorclass AihuRadioGroupIndicator extends HTMLElementBasePresentational styling hook: mirrors its enclosing ITEM's state (nearest `radioGroupItemContext` provider), hidden from AT.
AihuRadioGroupItemclass AihuRadioGroupItem extends HTMLElementBaseAihuRadioGroupRootclass AihuRadioGroupRoot extends AihuRovingFocusAihuRovingFocusclass AihuRovingFocus extends HTMLElementBaseAihuSeparatorclass AihuSeparator extends HTMLElementBaseAihuSliderRootclass AihuSliderRoot extends HTMLElementBaseAihuSwitchRootclass AihuSwitchRoot extends HTMLElementBaseAihuSwitchThumbclass AihuSwitchThumb extends HTMLElementBasePresentational styling hook: mirrors the root's state, hidden from AT.
AihuTextareaclass AihuTextarea extends AihuTextControlBaseAihuTextControlBaseabstract class AihuTextControlBase extends HTMLElementBaseAihuTooltipContentclass AihuTooltipContent extends HTMLElementBaseAihuTooltipRootclass AihuTooltipRoot extends HTMLElementBaseAihuTooltipTriggerclass AihuTooltipTrigger extends HTMLElementBaseMissingContextErrorclass MissingContextError extends ErrorThrown by `injectContext` when no provider is found and the token has no default.
CheckboxContextValueinterface CheckboxContextValue {
readonly state: Read<CheckboxState>
readonly disabled: Read<boolean>
}CollectionContextValueinterface CollectionContextValue {
/** Register `el`; returns a disposer that unregisters it. */
register(el: Element): () => void
/** Registered descendants, kept in DOM order. */
readonly items: Read<Element[]>
}ConfigContextValueinterface ConfigContextValue {
readonly colorScheme: Read<ColorScheme>
readonly density: Read<Density>
readonly dir: Read<Direction>
}DialogContextValueinterface DialogContextValue {
readonly open: Read<boolean>
readonly modal: Read<boolean>
readonly contentId: Read<string>
readonly titleId: Read<string | null>
readonly descriptionId: Read<string | null>
setTitleId(id: string): void
setDescriptionId(id: string): void
setOpen(next: boolean): void
close(): void
toggle(): void
}DomContextinterface DomContext<T> {
readonly _key: symbol
readonly _name: string
readonly _default: T | undefined
}Opaque token identifying a context slot.
FocusTrapinterface FocusTrap {
activate(): void
deactivate(): void
}FocusTrapOptionsinterface FocusTrapOptions {
/**
* CSS selector, resolved against the container's COMPOSED subtree (so it can
* match into a nested open shadow root), naming the element to focus on
* `activate()`. Falls back to the first tabbable — the default behavior —
* when absent or when the selector matches nothing.
*/
initialFocus?: string | null
/**
* Restore focus to whatever was focused before `activate()` when the trap is
* deactivated. Defaults to `true`; pass `false` to opt out (the trap then
* leaves focus wherever it currently is).
*/
returnFocus?: boolean
}FormControlContextValueinterface FormControlContextValue {
readonly disabled: Read<boolean>
readonly required: Read<boolean>
readonly invalid: Read<boolean>
readonly controlId: Read<string>
readonly describedById: Read<string | null>
readonly labelId: Read<string | null>
}HiddenInputOptionsinterface HiddenInputOptions {
type: 'checkbox' | 'radio'
name: Read<string | null>
value: Read<string>
checked: Read<boolean>
required: Read<boolean>
disabled: Read<boolean>
}PopoverContextValueinterface PopoverContextValue {
readonly open: Read<boolean>
readonly contentId: Read<string>
readonly placement: Read<Placement>
/** Resolved position written by the content after each `position()` call. */
readonly coords: Read<PopoverCoords | null>
setCoords(next: PopoverCoords): void
/** Programmatic write — signal + reflected attribute, does NOT emit. */
setOpen(next: boolean): void
/** User-driven toggle (trigger click / Enter / Space) — emits. */
toggle(): void
/** User-driven close WITHOUT returning focus (outside pointerdown). */
close(): void
/** User-driven close that RETURNS focus to the trigger (Escape). */
dismiss(): void
registerTrigger(el: Element): void
registerContent(el: Element): void
triggerEl(): Element | null
}PopoverCoordsinterface PopoverCoords {
x: number
y: number
placement: Placement
}The position the shim actually applied (post viewport-collision flip).
RadioGroupContextValueinterface RadioGroupContextValue {
/** Currently selected item value; null when nothing is selected. */
readonly value: Read<string | null>
/** Group-effective disabled (own attribute ∥ inherited form-control). */
readonly disabled: Read<boolean>
readonly required: Read<boolean>
/** Programmatic write: signal + reflected `value` attribute. NO event. */
setValue(next: string | null): void
/** USER-driven selection of `item` (click path): moves the tab stop to the
* item WITHOUT stealing focus, selects its value, emits `value-change`. */
selectItem(item: Element): void
}RadioGroupItemContextValueinterface RadioGroupItemContextValue {
readonly checked: Read<boolean>
readonly disabled: Read<boolean>
}Per-item context so `<aihu-radio-group-indicator>` mirrors its OWN item (nearest-provider-wins walk lands on the enclosing item, not the root).
SliderContextValueinterface SliderContextValue {
readonly value: Read<number>
readonly min: Read<number>
readonly max: Read<number>
readonly step: Read<number>
readonly disabled: Read<boolean>
}SwitchContextValueinterface SwitchContextValue {
readonly checked: Read<boolean>
readonly disabled: Read<boolean>
}TooltipContextValueinterface TooltipContextValue {
readonly open: Read<boolean>
readonly contentId: Read<string>
readonly placement: Read<Placement>
readonly openDelay: Read<number>
readonly closeDelay: Read<number>
setOpen(next: boolean): void
/** Schedule open/close honoring the configured delays. */
scheduleOpen(): void
scheduleClose(): void
/** Immediate dismiss (Escape). */
dismiss(): void
registerTrigger(el: Element): void
triggerEl(): Element | null
}TooltipCoordsinterface TooltipCoords {
x: number
y: number
placement: Placement
}ButtonTypetype ButtonType = 'button' | 'submit' | 'reset'CheckboxStatetype CheckboxState = 'checked' | 'unchecked' | 'indeterminate'ColorSchemetype ColorScheme = 'light' | 'dark' | 'system'Densitytype Density = 'comfortable' | 'compact'Directiontype Direction = 'ltr' | 'rtl'Orientationtype Orientation = 'horizontal' | 'vertical' | 'both'SeparatorOrientationtype SeparatorOrientation = 'horizontal' | 'vertical'