password_manager/src/lib/autofocus.js

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())
}
}