Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown lists : auto close ? #5409

Closed
istrasoft opened this issue Jul 3, 2014 · 7 comments
Closed

Dropdown lists : auto close ? #5409

istrasoft opened this issue Jul 3, 2014 · 7 comments
Assignees
Milestone

Comments

@istrasoft
Copy link
Contributor

Hi,

I wonder, for dropdown of the list variety, shouldn't a click/touch on a list element automatically close the dropdown ?

My 2 cents

@rafibomb rafibomb added this to the Review milestone Aug 5, 2014
@rafibomb rafibomb assigned rafibomb and unassigned lozandier Sep 5, 2014
@rafibomb rafibomb modified the milestones: 5.4.1 , Review, 5.4.2 Sep 5, 2014
@rafibomb
Copy link
Member

rafibomb commented Sep 5, 2014

This component was not built with single page apps in mind. I think it would be good to have. Have you worked out a hook to close the drop-down?

@rafibomb rafibomb modified the milestones: 5.4.2, 5.4.4 Sep 9, 2014
@rafibomb rafibomb modified the milestones: 5.4.4 , 5.5 Oct 16, 2014
@rafibomb
Copy link
Member

A solution was posted here: http://foundation.zurb.com/forum/posts/2032-dropdown-button-not-toggling

Though I'm sure if this is the best way.

@melroy89
Copy link

melroy89 commented Dec 20, 2017

$(".nav-item").on( "click", function( event ) {        
    	if($('.navbar-toggler').is(':visible')) {    
            $(".navbar-toggler").trigger('click');
        }
});

@esfandyarp
Copy link

@Danger89's solution worked for me.

@Y3hu
Copy link

Y3hu commented Jul 29, 2020

I am working on a website with React and Bootstrap and had the same problem.
Here is the solution that worked for me (add it inside useEffect on the navigation component):

//get all nav items elements
let navItems = document.querySelectorAll(".nav-link")
//iterate the nav items and add a listener to each of them
navItems.forEach(item => item.addEventListener("click", () => {
    //validate if toggler button is displayed
    if (document.getElementById("button-toggler").offsetParent !== null) {
        //trigger click event of the toggler button
        document.getElementById("button-toggler").click()
    }
}))

@DanielRuf
Copy link
Contributor

and Bootstrap

Just as a side note, mixing frameworks is rarely a good idea (there can be many conflicts).

@Y3hu
Copy link

Y3hu commented Jul 29, 2020

and Bootstrap

Just as a side note, mixing frameworks is rarely a good idea (there can be many conflicts).

Yep, I think the same but, I am not the one who makes desisions. xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants