@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
26 lines (25 loc) • 1.52 kB
TypeScript
import { type AnyKitForm, type FieldRegistration } from './formRuntime.js';
import type { ScopeHandle } from '../components/layouts/FieldScope/index.js';
/** Resolves after the next animation frame (React has committed by then). */
export declare function nextFrame(): Promise<void>;
/** The element itself if focusable, else its first focusable descendant. */
export declare function focusTarget(element: HTMLElement): HTMLElement | null;
/**
* Reveals the field's tab/accordion/step chain, then focuses its control.
*
* @privateRemarks Design reference §5.6.
*/
export declare function focusField(form: AnyKitForm, name: string): Promise<boolean>;
/** Sorts entries by the DOM order of their elements; unmounted elements last. */
export declare function sortByDomOrder<T extends {
element(): HTMLElement | null;
}>(entries: readonly T[]): T[];
/** Registered, active fields that currently have an error, in DOM order (optionally within a scope). */
export declare function invalidFields(target: AnyKitForm, within?: ScopeHandle): [string, FieldRegistration][];
/**
* After a frame (so `aria-invalid` is committed), focuses the first invalid field in DOM order,
* revealing its tab/accordion/step first. Resolves `true` when something got focus.
*/
export declare function focusFirstInvalid(form: AnyKitForm, within?: ScopeHandle): Promise<boolean>;
/** Applies the form's `focusOnInvalid` policy after an invalid submit. */
export declare function focusOnInvalidSubmit(form: AnyKitForm): Promise<boolean>;