SideNav and overlay behaviour on click
See original GitHub issueWhat package(s) are you using?
-
carbon-components
-
carbon-components-react
Detailed description
I use the UI shell with a SideNav, and a HashRouter, similar to what’s described in the Carbon React tutorial.
On small or medium viewports, when you click on the HeaderMenuButton, the SideNav is expanded, and the rest of the page content is masked by a gray overlay.
Then there are 2 related issues:
- If the user clicks on a SideNavLink, the content loads into the content area, but the SideNav remains expanded, and does not close, as is expected.
- If the user wants to close the SideNav (as a result of 1, or simply because he wants to remain on the same page), he must click on the HeaderMenuButton (currently displaying as a cross). Clicking anywhere on the overlay or the menu bar does not close the SideNav as expected.
In both cases, user expects the SideNav to be closed after a click inside or outside of it, because that’s the way most apps behave.
Bug seems browser-independent.
Using Node.js 10.16.2 (LTS). Dependencies and versions from package.json
:
"dependencies": {
"@carbon/grid": "^10.4.0",
"@carbon/icons-react": "^10.4.1",
"carbon-components": "^10.4.1",
"carbon-components-react": "^7.4.1",
"carbon-icons": "^7.0.7",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1"
},
Steps to reproduce the issue
Setup project with the UI Shell like in the Carbon React tutorial:
- use <HashRouter> and <Link> from react-router-dom
- App structure (stripped pseudo-code, does not contain the Router):
<HeaderContainer render={ ({ isSideNavExpanded, onClickSideNavExpand }) => (
<>
<Header>
<SkipToContent />
<HeaderMenuButton onClick={onClickSideNavExpand} isActive={isSideNavExpanded} />
<HeaderName>Name</HeaderName>
<SideNav expanded={isSideNavExpanded} isPersistent={false}>
<SideNavItems>
<SideNavLink element={Link} to="link1">Link 1</SideNavLink>
<SideNavLink element={Link} to="link2">Link 2</SideNavLink>
</SideNavItems>
</SideNav>
</Header>
<p>Content area</p>
</>
)}
/>
Additional information
Picture below shows a prototype: clicking on any of the zones pointed to by an arrow should close the side navigation.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Subscribing to sidenav overlay click - MDBootstrap
Dear mdb2, There's no possibility to subscribe to sidenav overlay click to check when the sidebar is closing. But you can achieve similar...
Read more >on Click body close sidebar menu - javascript - Stack Overflow
Just write the click function on body-overlay $('.body-overlay').click(function(){ $('.panel-arrow').trigger('click'); });.
Read more >Sidenav with custom escape and backdrop click behavior
Sidenav with custom escape and backdrop click behavior.
Read more >Sidenav - Angular Material
The sidenav has the ability to capture focus. This behavior is turned on for the push and over modes and it is off...
Read more >Overlay Sidenav - CodePen
A sidenav study. When opened, this sidenav covers the content. The content area becomes unscrollable and is slightly faded into the background, until...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nxn-4-wdf yo. i ran into another problem where the sidenav stays there if you resize the browser so i amended the code to look like this. this fixes both the click out issue you describes as well as a broken ghosted sidenav on resize
@nxn-4-wdf hey man, i ran into this problem too. just change your <Header component to look like this:
tadaaaaa