Fix window is undefined

Moving global window access to onMount hook for to fix "window is undefined" error when using with sapper, etc.
This commit is contained in:
Amandeep 2020-03-08 00:32:44 -05:00 committed by GitHub
commit c329008e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,10 +14,13 @@
import UIShellSideNavWrapper from './UIShellSideNav/UIShellSideNavWrapper.svelte'; import UIShellSideNavWrapper from './UIShellSideNav/UIShellSideNavWrapper.svelte';
import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte'; import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte';
import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte'; import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte';
import { onMount } from 'svelte'
let isSideNavOpen = undefined; let isSideNavOpen = undefined;
let winWidth = window.innerWidth; let winWidth = undefined;
onMount(() => {
winWidth = window.innerWidth
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
winWidth = window.innerWidth; winWidth = window.innerWidth;
@ -27,6 +30,7 @@
isSideNavOpen = false; isSideNavOpen = false;
} }
}); });
})
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName); $: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
</script> </script>