10 lines
265 B
JavaScript
10 lines
265 B
JavaScript
/**
|
|
* Action that autofocuses an element after mount when the condition is truthy.
|
|
* Uses a microtask to ensure the element is fully rendered.
|
|
*/
|
|
export function autofocus(node, condition = true) {
|
|
if (condition) {
|
|
queueMicrotask(() => node.focus())
|
|
}
|
|
}
|