rework to use tick instead of manual timeout

This commit is contained in:
Keviin Åberg Kultalahti 2021-04-14 10:25:10 +02:00
parent 5d1d53f679
commit fa08a6211d
1 changed files with 4 additions and 18 deletions

View File

@ -2,7 +2,7 @@
import "@spectrum-css/dialog/dist/index-vars.css" import "@spectrum-css/dialog/dist/index-vars.css"
import "@spectrum-css/modal/dist/index-vars.css" import "@spectrum-css/modal/dist/index-vars.css"
import "@spectrum-css/underlay/dist/index-vars.css" import "@spectrum-css/underlay/dist/index-vars.css"
import { createEventDispatcher, setContext } from "svelte" import { createEventDispatcher, setContext, tick } from "svelte"
import { fade, fly } from "svelte/transition" import { fade, fly } from "svelte/transition"
import Portal from "svelte-portal" import Portal from "svelte-portal"
import Context from "../context" import Context from "../context"
@ -31,25 +31,11 @@
} }
} }
function focusFirstInput(node) { async function focusFirstInput(node) {
const inputs = node.querySelectorAll('input') const inputs = node.querySelectorAll('input')
console.log(inputs)
let timer;
if (inputs) { if (inputs) {
timer = setTimeout(() => { await tick()
inputs[0].focus() inputs[0].focus()
}, 20)
}
return {
destroy() {
if (timer) {
clearTimeout(timer)
}
}
} }
} }