Let a native host quiet a focused editor while the person reads, without losing their place. Install the separate lib-use-resting-caret helper for use with TextField, TextArea or Composer. Omit this helper on ordinary web pages.
Permission comes from the host
Enable this only in a native host that can meet the whole contract below. Do not copy the demo's simulated permission into an app.
- Keep
enabledfalse when assistive technology or voice input is on, or its state is unknown. Do not infer this permission from reduced motion. - Supply
subscribeWake(wake), returning an unsubscribe function. Callwake()synchronously before opening a native editing menu, delivering dictation, inserting from a character palette or forwarding other native input. - Supply
onHeld(held). While held, intercept native input-method keys before the engine receives them, request a wake and forward the keys only afteronHeld(false). Include dead keys, modifier keys and the Globe key. - Pass
occludedwhen the host knows the window is covered or minimised. - Keep both callbacks stable. Change
enabledto revoke permission.
Engines that support caret-animation: manual keep their own steady caret without changing editability.native-animation Other engines temporarily change the editor's editability, not just its caret colour. That fallback is why a host bridge is required: input that bypasses page events needs to wake the editor first. A browser page cannot establish that contract by itself.
import { useState } from "react";
import { TextArea } from "@/components/ouro/text-area";
import { useRestingCaret } from "@/lib/ouro/use-resting-caret";
function Draft({ readOnly, disabled }: { readOnly: boolean; disabled: boolean }) {
const [box, setBox] = useState<HTMLInputElement | HTMLTextAreaElement | HTMLDivElement | null>(null);
useRestingCaret(box, {
enabled: host.caretRestPermitted,
occluded: host.windowCovered,
subscribeWake: host.subscribeCaretWake,
onHeld: host.setCaretHeld,
}, readOnly, disabled);
return <TextArea ref={setBox} label="Draft" autoGrow readOnly={readOnly} disabled={disabled} />;
}These are methods supplied by your host, not browser APIs. For an app without this bridge, omit useRestingCaret.
Pass the same readOnly and disabled state to the hook and the field: while held, the hook's own read-only state cannot identify a new caller-owned restriction. Use the state setter as the callback ref, not an object ref, so the hook can follow a replacement editor. Pass ref={setBox} to TextField or Composer too; Composer's rich editor uses a div rather than a textarea.ref When changing a TextField's native type, pass that value as the hook's fifth argument too.
The helper is separate from the components' props. The item tests exercise the helper with each actual editor, including plain-to-rich replacement.ref
A quiet place to return to
After thirty seconds without editing input, the focused editor shows a steady caret for a collapsed selection.idle Typing wakes it in capture phase, before the page's input handlers run; pointer movement and scrolling do not wake it.idle
A composing word stays editable, and changing the host's permission to false releases a hold. A caller's own readOnly remains the caller's.safety Native input types that expose no text selection keep their own caret.native
Page visibility and the host's cover signal also control the hold. A hidden page draws no replacement caret; an unfocused window keeps the engine's own caret behaviour.visibility The editor's data-caret-rest attribute exposes the current reason for inspection.
The fallback's steady caret is decoration, hidden from assistive technology. Text selection, including its direction, stays in the original control.selection Waking from the fallback starts a new native typing run; do not promise a single undo group across a rest.
Try Try quiet reading in the TextArea demo, then type without clicking the field again. Do not use this simulated host as an accessibility detector.
Prior art
Borrow the idle hold and host-wake contract from a consuming app, with permission kept explicit rather than enabled for the open web. Adopt the CSS caret-animation: manual property where supported: the engine owns its caret, with no replacement to position.native-animationcss
Claim sources
- idle: The source file text-area.resting-caret.test.tsx; The source file use-resting-caret.ts
Checks
- A line matching /const afterIdle = 30_000;/ is in use-resting-caret.ts
- A test with this name exists: TextArea resting caret > rests after thirty seconds, keeps focus and selection, and inserts the first waking character
- A test with this name exists: TextArea resting caret > wakes for host input and composition, but not reading with the pointer or wheel
- safety: The source file text-area.resting-caret.test.tsx
Checks
- A test with this name exists: TextArea resting caret > leaves caller readOnly alone and releases a hold when host safety changes
- A test with this name exists: TextArea resting caret > does not undo a caller's readOnly change made while held
- selection: The source file text-field.resting-caret.test.tsx
Checks
- A test with this name exists: TextField resting caret > keeps a backward selection and accepts the first character after a host wake
- native: The source file use-resting-caret.ts
Checks
- A line matching /if \(textBox\(box\) && box\.selectionStart === null\) return;/ is in use-resting-caret.ts
- visibility: The source file use-resting-caret.ts
Checks
- A line matching /if \(visible && foreground\)/ is in use-resting-caret.ts
- css: The page at developer.mozilla.org
Checks
- The page it cites opens
- native-animation: The source file use-resting-caret.test.tsx
Checks
- A test with this name exists: resting caret host contract > uses the engine's steady caret when supported and restores the caller's animation
- ref: The source file composer.resting-caret.test.tsx
Checks
- A test with this name exists: Composer resting caret > reattaches to a rich editor without losing its insertion point after a held empty plain editor

