Files
CatoandClaude 3a3384c5b8 feat(field): DictationField can stand in for a form's text area (0.27.0) (#85)
* feat(field): DictationField in a form — name, error, submit keys, field-level focus (0.27.0)

Loki's 36 hand-made text areas could not become DictationField because a
form needs props the field did not pass through (measured: onKeyDown 10,
maxLength 9, id 7, autoFocus 7, disabled 5, onBlur 2, onFocus 1, name 2,
spellCheck 1, plus validation errors on the field).

- name, autoFocus, readOnly (no mic, no Improve, no Undo)
- invalid / error: aria-invalid, the frame in --ck-danger, the error under
  the field as role=alert, error and hint linked with aria-describedby
- onKeyDown, and onSubmit owned by the package: Cmd/Ctrl+Enter in a text
  area, Enter in one line; never while composing, disabled, read-only or
  during a take
- onFocus / onBlur for the whole field: the mic is not a blur, and a blur
  during a take is held until its words reach onValueChange
- inputProps for spellCheck, autoComplete, inputMode, aria-*, data-*;
  managed props win
- Enter in Improve's instruction box applies it

Tests: server markup in render.test.js; a Strict Mode form fixture in
browser-field.mjs at 390px and desktop, light and dark, and 320px with an
error shown. Version 0.27.0 (0.26.0 is already on npm).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

* fix(field): Improve at work is not a blur; Enter never sends the native form mid-take

Review findings on the 0.27.0 DictationField form props:
- Improve disables its own box and button while it works, so focus fell off
  with nowhere to go and the field reported a blur. Improve at work now
  counts as busy, like a take.
- With onSubmit, Enter in a one-line field (Shift+Enter, during a take,
  read-only) no longer runs the browser's implicit form post.
- error="" or 0 is no error: no danger frame, no aria-invalid with nothing said.
- inputProps.style no longer reaches the box (16px text is the package's).
- The form fixture loads a development bundle, so Strict Mode is exercised.
- README and CHANGELOG: a held blur is not reported if the host unmounts
  the field; the hint's aria-describedby is the one markup change.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsyW2aAn78GgfRxyn5

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 08:58:49 +01:00

34 lines
1.7 KiB
TypeScript

import { type FocusEvent as ReactFocusEvent } from "react";
/**
* Focus for a whole field, not for one element in it.
*
* A field is a text box, a microphone, Improve and the improve panel. A host
* that saves and closes an inline editor on blur must not see a blur when
* focus moves between those parts, or the editor closes under the person's
* finger as they press the microphone. So `onFocus` fires when focus enters
* the field and `onBlur` when it leaves it; moves inside are not reported.
*
* Focus can also go nowhere (`relatedTarget` null): a tap on empty page, a
* button that takes no focus (Safari), a control the field itself removes or
* disables while busy, or the window losing focus. Once focus has settled
* the field decides: back inside, or the window switched away → still here; a
* recent press inside → still here (the press was on the field); a recent
* press outside → left. Until a later press or focus lands outside, the field
* counts as focused, and the document listeners report the blur then.
*
* A blur while `busy` (a take is recorded or transcribed, or Improve is at
* work) is held and reported once that has ended, which is after a take's
* words were delivered, so a host that unmounts the field on blur never loses
* what was said. A field unmounted while its blur is held reports none: the
* words still reach `onValueChange`, the blur does not.
*/
export declare function useFieldFocus({ busy, onFocus, onBlur, }: {
busy: boolean;
onFocus?: () => void;
onBlur?: () => void;
}): {
wrapRef: import("react").RefObject<HTMLDivElement | null>;
onFocus: () => void;
onBlur: (e: ReactFocusEvent<HTMLDivElement>) => void;
};
//# sourceMappingURL=field-focus.d.ts.map