File size: 249 Bytes
fbef5e8
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import { tick } from "svelte";
import type { Attachment } from "svelte/attachments";

export function autofocus(enabled = true): Attachment<HTMLElement> {
	return node => {
		if (!enabled) return;

		tick().then(() => {
			node.focus();
		});
	};
}