question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fixed sidenav with closeOnClick enabled

See original GitHub issue

So, currently, if you have a fixed sideNav and you want closeOnClick “enabled” for your mobile side, you have to add in a work around to make sure that if a user clicks and is on a full desktop version, it doesn’t hide the side nav when it should be fixed.

TLDR; You can’t have closeOnClick enabled with a fixed side nav

A workaround I created for this is:

  // Side Navigation fix
  $('.side-nav li a').on('click', function(e) {
    windowsize = $(window).width();
    if (windowsize < 992) {
      $('.button-collapse').sideNav('hide');
    }
  });

This is probably something to look into since it is useful to have the sidenav close on click on mobile, but stay fixed on desktop screens.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Davis152commented, Jan 22, 2018

sorry guys, i tried to hide the navbar afeter click un the links, but doesnt work, Where, i have to put this code.

if (window.matchMedia(“(min-width: 992px)”).matches) { /* the viewport is at least 992 pixels wide / $(‘.button-collapse’).sideNav({ closeOnClick: false, // Closes side-nav on clicks, useful for Angular/Meteor } ); } else { / the viewport is less than 992 pixels wide */ $(‘.button-collapse’).sideNav({ closeOnClick: true, // Closes side-nav on clicks, useful for Angular/Meteor } ); }

i am working with react and materialize.

thanks in advance.

netopapacommented, Jun 27, 2017

It works! Valeu, parceiro

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixed SideNav not Compatible with closeOnClick
If you have a fixed SideNav and you initialize it with closeOnClick: true, then clicking an item closes the SideNav. I expected the...
Read more >
CloseOnClick property in sideNav should only be ...
Here I have specified 'fixed' style which keeps the sideNav fixed for larger screens and it hides the sideNav for smaller screens. This...
Read more >
Disable closing of sideNav when click outside the sideNav
MaterializeCSS doesn't have a built-in method for achieve this task, but you can use a workaround, unbinding the click event from sideNav overlay:...
Read more >
The width of your desired sidenav - GWT Material Design
closeOnClick - If clicked on the sidemenu items it will be automatically closed if set ... width="300" m:id="mysidebar" type="FIXED" closeOnClick="false">
Read more >
react-pro-sidebar
Start using react-pro-sidebar in your project by running `npm i ... A function that enables you to update the sidebar's collapsed state.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found