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,19 +14,23 @@
import UIShellSideNavWrapper from './UIShellSideNav/UIShellSideNavWrapper.svelte';
import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte';
import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte';
import { onMount } from 'svelte'
let isSideNavOpen = undefined;
let winWidth = window.innerWidth;
let winWidth = undefined;
window.addEventListener('resize', () => {
winWidth = window.innerWidth;
onMount(() => {
winWidth = window.innerWidth
window.addEventListener('resize', () => {
winWidth = window.innerWidth;
if (winWidth >= 1056) {
isSideNavOpen = true;
} else {
isSideNavOpen = false;
}
});
if (winWidth >= 1056) {
isSideNavOpen = true;
} else {
isSideNavOpen = false;
}
});
})
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
</script>