simplify autofocus

blockless
Rich Harris 2 years ago
parent 529f9872bd
commit ba0eed1d53

@ -488,24 +488,19 @@ export function text(dom, value) {
} }
/** /**
* @param {HTMLElement} dom * @param {HTMLElement} element
* @param {boolean} value * @param {boolean} value
* @returns {void} * @returns {void}
*/ */
export function auto_focus(dom, value) { export function auto_focus(element, value) {
if (value) { if (value) {
const body = document.body; element.autofocus = true;
dom.autofocus = true;
render_effect( user_effect(() => {
() => { if (document.activeElement === document.body) {
if (document.activeElement === body) { element.focus();
dom.focus(); }
} });
},
current_block,
true,
false
);
} }
} }

Loading…
Cancel
Save