From fa08a6211d40a9a728f6509f66e0058e22da1194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Wed, 14 Apr 2021 10:25:10 +0200 Subject: [PATCH] rework to use tick instead of manual timeout --- packages/bbui/src/Modal/Modal.svelte | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/bbui/src/Modal/Modal.svelte b/packages/bbui/src/Modal/Modal.svelte index 7c23126fa7..10e3db35c6 100644 --- a/packages/bbui/src/Modal/Modal.svelte +++ b/packages/bbui/src/Modal/Modal.svelte @@ -2,7 +2,7 @@ import "@spectrum-css/dialog/dist/index-vars.css" import "@spectrum-css/modal/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 Portal from "svelte-portal" import Context from "../context" @@ -31,25 +31,11 @@ } } - function focusFirstInput(node) { + async function focusFirstInput(node) { const inputs = node.querySelectorAll('input') - - console.log(inputs) - - let timer; - if (inputs) { - timer = setTimeout(() => { - inputs[0].focus() - }, 20) - } - - return { - destroy() { - if (timer) { - clearTimeout(timer) - } - } + await tick() + inputs[0].focus() } }