Merge pull request #207 from IBM/fix-modal-ssr

fix(modal): replace onDestroy with onMount for SSR support
This commit is contained in:
Eric Liu 2020-07-19 14:17:52 -07:00 committed by GitHub
commit cd340d1fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,7 @@
export let id = "ccs-" + Math.random().toString(36); export let id = "ccs-" + Math.random().toString(36);
export let ref = null; export let ref = null;
import { createEventDispatcher, afterUpdate, onDestroy } from "svelte"; import { createEventDispatcher, onMount, afterUpdate } from "svelte";
import Close20 from "carbon-icons-svelte/lib/Close20"; import Close20 from "carbon-icons-svelte/lib/Close20";
import { Button } from "../Button"; import { Button } from "../Button";
@ -33,6 +33,12 @@
node.focus(); node.focus();
} }
onMount(() => {
return () => {
document.body.classList.remove("bx--body--with-modal-open");
};
});
afterUpdate(() => { afterUpdate(() => {
if (opened) { if (opened) {
if (!open) { if (!open) {
@ -48,10 +54,6 @@
} }
}); });
onDestroy(() => {
document.body.classList.remove("bx--body--with-modal-open");
});
$: modalLabelId = `bx--modal-header__label--modal-${id}`; $: modalLabelId = `bx--modal-header__label--modal-${id}`;
$: modalHeadingId = `bx--modal-header__heading--modal-${id}`; $: modalHeadingId = `bx--modal-header__heading--modal-${id}`;
$: ariaLabel = $: ariaLabel =