aihu headless behavior primitives — WAI-ARIA APG patterns as vanilla custom elements, zero CSS.
createCollectionfunction createCollection()The registration mechanism, usable standalone (roving-focus reuses it).
createDomContextfunction createDomContext<T>(name: string, defaultValue?: T): DomContext<T>Create a context token.
defineCheckboxfunction defineCheckbox()Register all checkbox custom elements (idempotent).
defineCollectionfunction defineCollection(tag = "aihu-collection")Register `<aihu-collection>` (idempotent).
defineConfigProviderfunction defineConfigProvider(tag = "aihu-config-provider")Register `<aihu-config-provider>` (idempotent).
defineInputfunction defineInput(tag = "aihu-input")Register `<aihu-input>` (idempotent).
defineLabelfunction defineLabel(tag = "aihu-label")Register `<aihu-label>` (idempotent).
definePresenceGatefunction definePresenceGate(tag = "aihu-presence-gate")Register `<aihu-presence-gate>` (idempotent — safe to call repeatedly).
defineRadioGroupfunction defineRadioGroup()Register all radio-group custom elements (idempotent).
defineRovingFocusfunction defineRovingFocus(tag = "aihu-roving-focus")Register `<aihu-roving-focus>` (idempotent).
defineSeparatorfunction defineSeparator(tag = "aihu-separator")Register `<aihu-separator>` (idempotent).
defineSwitchfunction defineSwitch()Register all switch custom elements (idempotent).
defineTextareafunction defineTextarea(tag = "aihu-textarea")Register `<aihu-textarea>` (idempotent).
defineTooltipfunction defineTooltip(prefix = "aihu")Register 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`.
AihuButtonconst AihuButtonAihuCheckboxIndicatorconst AihuCheckboxIndicatorPresentational styling hook: mirrors the root's state, hidden from AT.
AihuCheckboxRootconst AihuCheckboxRootAihuCollectionconst AihuCollectionAihuConfigProviderconst AihuConfigProviderAihuDialogBackdropconst AihuDialogBackdropAihuDialogCloseconst AihuDialogCloseAihuDialogContentconst AihuDialogContentAihuDialogDescriptionconst AihuDialogDescriptionAihuDialogRootconst AihuDialogRootAihuDialogTitleconst AihuDialogTitleAihuDialogTriggerconst AihuDialogTriggerAihuFormControlconst AihuFormControlAihuInputconst AihuInputAihuLabelconst AihuLabelAihuPresenceGateconst AihuPresenceGateAihuRadioGroupIndicatorconst AihuRadioGroupIndicatorPresentational styling hook: mirrors its enclosing ITEM's state (nearest `radioGroupItemContext` provider), hidden from AT.
AihuRadioGroupItemconst AihuRadioGroupItemAihuRadioGroupRootconst AihuRadioGroupRootAihuRovingFocusconst AihuRovingFocus`<aihu-roving-focus>` — WAI-ARIA roving-tabindex container.
AihuSeparatorconst AihuSeparator`<aihu-separator>` — headless separator (WAI-ARIA APG Separator, static variant).
AihuSwitchRootconst AihuSwitchRootAihuSwitchThumbconst AihuSwitchThumbPresentational styling hook: mirrors the root's state, hidden from AT.
AihuTextareaconst AihuTextareaAihuTextControlBaseconst AihuTextControlBaseAihuTooltipContentconst AihuTooltipContentAihuTooltipRootconst AihuTooltipRootAihuTooltipTriggerconst AihuTooltipTriggerattachHiddenInputconst attachHiddenInputButtonTypeconst ButtonTypecheckboxContextconst checkboxContextHeadless checkbox — `<aihu-checkbox-root>` (state owner) + presentational `<aihu-checkbox-indicator>`.
collectionContextconst collectionContext`<aihu-collection>` — descendant-registration substrate (the Radix `Collection` pattern) implemented over the DOM-walk context.
configContextconst configContext`<aihu-config-provider>` — app-level config propagated via reactive DOM context.
createFocusTrapconst createFocusTrapdefineButtonconst defineButtondefineDialogconst defineDialogdefineFormControlconst defineFormControldialogContextconst dialogContextDialogContextValueconst DialogContextValueFocusTrapconst FocusTrapformControlContextconst formControlContextFormControlContextValueconst FormControlContextValueHiddenInputOptionsconst HiddenInputOptionspresenceContextconst presenceContextContext carrying the gate's `present` signal to descendants.
radioGroupContextconst radioGroupContextHeadless radio group — `<aihu-radio-group-root>` (state owner, EXTENDS `AihuRovingFocus`) + `<aihu-radio-group-item>` (role="radio") + presentational `<aihu-radio-group-indicator>`.
radioGroupItemContextconst radioGroupItemContextswitchContextconst switchContextHeadless switch — `<aihu-switch-root>` (state owner) + presentational `<aihu-switch-thumb>`.
tooltipContextconst tooltipContextHeadless tooltip — `<aihu-tooltip-root>` + `<aihu-tooltip-trigger>` + `<aihu-tooltip-content>`.
MissingContextErrorclass 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>;
}DomContextinterface DomContext<T> {
readonly _key: symbol
readonly _name: string
readonly _default: T | undefined
}Opaque token identifying a context slot.
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).
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;
}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';