Skip to content

Headless Core — Input

Powers Input internally. The smallest state shape in the package — no keyboard handler, since text entry is native browser behavior the factory doesn’t need to intercept.

import { createInput } from '@andersseen/headless-components/input';
const input = createInput({
defaultValue: '',
required: true,
onValueChange: value => console.log('Value:', value),
});
input.actions.setValue('hello');
input.queries.isValid(); // true — non-empty and required is satisfied
OptionTypeDefaultNotes
defaultValuestring''
disabledbooleanfalse
requiredbooleanfalse
maxLengthnumberForwarded as maxlength.
onValueChange(value: string) => voidNot called if disabled.

value, disabled, required, touched (set on blur()), focused.

MemberSignatureNotes
actions.setValue(v)(value: string) => voidNo-ops if disabled.
actions.setDisabled(v)(disabled: boolean) => void
actions.setRequired(v)(required: boolean) => void
actions.focus()() => voidNo-ops if disabled; sets focused: true.
actions.blur()() => voidSets focused: false and touched: true.
queries.isEmpty()() => boolean
queries.isValid()() => booleanAlways true unless required and empty.

getInputProps() returns type: 'text', value, disabled, required, maxlength, aria-disabled, aria-required, aria-invalid (only true once the field has been touched and is empty and required — so it doesn’t flag invalid before the user has had a chance to type anything), data-state.


Type something, then clear it and click away — aria-invalid flips to true only after the field has been touched.

Select — a richer relative with an options list, open state, and typeahead.