carbon-components-svelte icon indicating copy to clipboard operation
carbon-components-svelte copied to clipboard

SideNav closed by default

Open HassanYA opened this issue 4 years ago • 6 comments

I am using sapper for development. idk if this issue is related to documentation or otherwise. I just copied and pasted the code from there and it did not exactly produced what it showed there.

Code is exactly as in Header with persisted hamburger menu and I had all of it inside a single component

The result: Screenshot_2020-12-19 sapper

What it is suppose to produce: Screenshot_2020-12-19 Carbon Components Svelte

https://carbon-svelte.vercel.app/framed/UIShell/PersistedHamburgerMenu?theme=g10

On Desktop screens, the side nav icon should be there and should be unopened by default. On Mobile, the behavior is as desired

HassanYA avatar Dec 19 '20 01:12 HassanYA

Hi @HassanYA :wave: may you provide a reproducible example?

josefaidt avatar Dec 21 '20 15:12 josefaidt

@HassanYA, have you tried setting expandedByDefault to false? <Header ... expandedByDefault={false}>

yollov avatar Feb 13 '21 22:02 yollov

isSideNavOpen handling appears to be broken. Setting isSideNavOpen to true on component creation will close the side nav:

let winWidth = undefined;
$: isSideNavOpen =
    expandedByDefault && winWidth >= 1056 && !persistentHamburgerMenu;

This is always false, so the sidebar is closed. Example here.

angrytongan avatar May 03 '21 09:05 angrytongan

@angrytongan Could you try this? I threw the UI Shell Header Nav example into a Svelte REPL.

Screen Shot 2021-05-03 at 7 47 13 AM

metonym avatar May 03 '21 14:05 metonym

G'day @metonym My example comes from the same place. When isSideNavOpen set to false at component creation, the side nav isn't open which is correct. However setting it to true at component creation doesn't open the side nav; Header sets isSideNavOpen to false because this test is always false:

$: isSideNavOpen =
    expandedByDefault && winWidth >= 1056 && !persistentHamburgerMenu;

I think winWidth is unchanged when isSideNavOpen is set in Header at component creation, so this will be false. Check the console output in my example.

angrytongan avatar May 03 '21 20:05 angrytongan

I think winWidth is unchanged when isSideNavOpen is set in Header at component creation, so this will be false. Check the console output in my example.

that helped me so much to find out why it wasn't working even though I was doing the correct usage of the isSideNavOpen. If you've forced persistentHamburgerMenu={true} in the UI shell header and use the rail mode then it will only work when you resize the window to reach the breakpoint If you have a full screen window then it doesnt work because the condition will be false.

Current condition is

  class:bx--side-nav--expanded="{rail && winWidth >= expansionBreakpoint
    ? false
    : isOpen}"
  class:bx--side-nav--collapsed="{!isOpen && !rail}"

To solve this I've set the expansionBreakpoint prop to100000 and now it works fine as it will go to the isOpen test

Something should probably be documented indicating "when in rail mode expansion is controlled by the breakpoint"

Edit: changed a bit my message as the initial issue wasnt about the rail mode

Sheepux avatar Aug 17 '22 22:08 Sheepux