autofocus.svelte.ts

Svelte 5 attachment that focuses an element on mount.

Declarations
#

view source

autofocus
#

autofocus.svelte.ts view source

(options?: FocusOptions | undefined): Attachment<HTMLElement | SVGElement>

Creates an attachment that focuses the element on mount. Use this instead of the HTML autofocus attribute for elements that mount dynamically from reactive conditionals like {#if}.

options?

focus options forwarded to element.focus(); defaults to {focusVisible: true} to show focus indicators on programmatic focus

type FocusOptions | undefined
optional

returns

Attachment<HTMLElement | SVGElement>