flowbite-react icon indicating copy to clipboard operation
flowbite-react copied to clipboard

navbar item on select doesn't collapse navbar

Open Ahmad-As7 opened this issue 3 years ago • 1 comments

Describe the bug when selecting a navbar Item on small screens Navbar should collapse but it doesn't.

Project information:

  • Flowbite React: 0.1.2

Ahmad-As7 avatar Sep 14 '22 06:09 Ahmad-As7

I'm not sure that it is a bug, once the Navbar collapse behaviour isn't given by flowbite-react out of the box, and you need to implement it by yourself.

However, I'm curious to see how it could be implemented, once it seems to be something that needs to be pass to the elements inside the navbar.

rluders avatar Sep 18 '22 08:09 rluders

See #329

rluders avatar Nov 06 '22 10:11 rluders

there's no isCollapsed property for NavBar Collapse, how do we proceed to implement this feature, if it's context based how do consume such context

ogheneovo12 avatar Aug 14 '23 06:08 ogheneovo12

I tried solving this using ref and even fowardRef, but could not get it working. So i used plain JavaScript to solve this.

Gave id to the NavbarToggle Component.

<NavbarToggle id='navbarToggleButton' />

Added onClick property to NavbarCollapse.

<NavbarCollapse onClick={toggleNavbarCollapse} >

The toggleNavbarCollapse implementation.

const toggleNavbarCollapse = () => {
    if (window.innerWidth <= 768) {
      const navbarToggleButton = document.getElementById('navbarToggleButton');
      if (navbarToggleButton) {
        navbarToggleButton.click(); // Simulate a click on NavbarToggle
      }
    }
  };

BhavyaJain711 avatar Mar 06 '24 21:03 BhavyaJain711

@BhavyaJain711 thank you, Bhavya! I just needed to add the .click() to my button event listener. Thank you so much, this has been a 5 hour fix for me and your comment helped me solve it!

findingfocus avatar May 21 '24 14:05 findingfocus

@findingfocus I'm glad it helped you. Sorry for late reply. I think this should be included in flowbite-react out of the box, and possibly add a prop to disable this. What do you think? I can't think of a use case when someone won't want it to collapse on select.

BhavyaJain711 avatar Jun 29 '24 16:06 BhavyaJain711