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