fn

writeInputState

v0.0.5tested

Writes value and selection back to an <input>/<textarea>. The value is only assigned when it actually changed (avoids spurious cursor jumps), and the caret is moved only while the element is focused so programmatic updates never steal or reposition focus. setSelectionRange is guarded because some input types (number, email, date) forbid it.

Example

ts
writeInputState(inputEl, { value: '(123)', selection: [5, 5] });

Signature

ts
export function writeInputState(element: TextFieldElement, state: InputState): void{ ... }

Parameters

ParameterTypeDescription
elementTextFieldElementThe input or textarea to update
stateInputStateThe { value, selection } to apply