fix(modal): focus

This commit is contained in:
Marcus Feitoza 2020-05-03 01:03:23 -03:00
commit 1340815417

View file

@ -19,7 +19,7 @@
export let size = undefined; export let size = undefined;
export let style = undefined; export let style = undefined;
import { createEventDispatcher, afterUpdate, onDestroy } from 'svelte'; import { createEventDispatcher, afterUpdate, onDestroy, onMount } from 'svelte';
import Close20 from 'carbon-icons-svelte/lib/Close20'; import Close20 from 'carbon-icons-svelte/lib/Close20';
import { cx } from '../../lib'; import { cx } from '../../lib';
import Button from '../Button'; import Button from '../Button';
@ -36,12 +36,14 @@
node.focus(); node.focus();
} }
afterUpdate(() => { onMount(() => {
if (open) {
focus(); focus();
dispatch('open'); dispatch('open');
document.body.classList.add(cx('--body--with-modal-open')); document.body.classList.add(cx('--body--with-modal-open'));
} else { })
afterUpdate(() => {
if (!open) {
dispatch('close'); dispatch('close');
document.body.classList.remove(cx('--body--with-modal-open')); document.body.classList.remove(cx('--body--with-modal-open'));
} }