// 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( 'input:not([type="checkbox"]):not([type="hidden"])' ); const empty = [...fields].find((f) => !f.value && !f.disabled); const target = empty ?? view.querySelector('button[data-primary]:not(:disabled)') ?? view.querySelector('button:not(:disabled)') ?? view.querySelector('h1'); target?.focus(); }