chadtmiller.com/monolith
An atproto PDS
0
0
// Where focus goes when a view appears (spec/OAUTH-PAGES.md, "Every
// page"): its first empty field, else its primary button, else its first
// button, else its heading.
export function focusFirst(view: HTMLElement): void {
const fields = view.querySelectorAll<HTMLInputElement>(
'input:not([type="checkbox"]):not([type="hidden"])'
);
const empty = [...fields].find((f) => !f.value && !f.disabled);
const target =
empty ??
view.querySelector<HTMLElement>('button[data-primary]:not(:disabled)') ??
view.querySelector<HTMLElement>('button:not(:disabled)') ??
view.querySelector<HTMLElement>('h1');
target?.focus();
}