fn

readInputState

v0.0.5tested

Reads the value and current selection of an <input>/<textarea> into a plain InputState. A null selection (some input types report it) falls back to a collapsed caret at the end of the value.

Example

ts
const { value, selection } = readInputState(inputEl);

Signature

ts
export function readInputState(element: TextFieldElement): InputState{ ... }

Parameters

ParameterTypeDescription
elementTextFieldElementThe input or textarea to read

Returns

InputStateThe element's { value, selection }
PropertyTypeDescription
valuestringThe element's current value.
selectionreadonly [from: number, to: number]The selection as [from, to] (collapsed caret when from === to).