[]previous and next page

Autofocus

autoFocus works as in React: an element that a client render or update inserts into the document takes focus, once.

For agentsUpdated

autoFocus works as in React: an element that a client render or update inserts into the document takes focus, once. It works on the first render, on an element a Show, For, Portal or Dialog inserts later, and on a {...spread} prop. A moved element (a keyed reorder) is not focused again. An element that is not connected when its owner renders (a detached root) is not focused.

During hydration the server markup already carries autofocus, so the browser focuses it at page load. The framework focuses the hydrated element only when nothing else has the focus (the active element is the body or none); a focus the user has already moved is never taken back. SSR keeps writing the autofocus attribute; the client does not write it.

A zero-cost rule: an app that never uses autoFocus does not import the runtime helper, so it adds no bytes.