mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
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:
parent
f085328279
commit
c329008e62
1 changed files with 16 additions and 12 deletions
|
@ -14,20 +14,24 @@
|
|||
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;
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
winWidth = window.innerWidth;
|
||||
|
||||
if (winWidth >= 1056) {
|
||||
isSideNavOpen = true;
|
||||
} else {
|
||||
isSideNavOpen = false;
|
||||
}
|
||||
});
|
||||
let winWidth = undefined;
|
||||
|
||||
onMount(() => {
|
||||
winWidth = window.innerWidth
|
||||
window.addEventListener('resize', () => {
|
||||
winWidth = window.innerWidth;
|
||||
|
||||
if (winWidth >= 1056) {
|
||||
isSideNavOpen = true;
|
||||
} else {
|
||||
isSideNavOpen = false;
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue