-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Problem in Dropdown in Bootstrap 4.2.1 #27903
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
Comments
/CC @Johann-S |
I'm unable to reproduce after upgrading from 4.1.3 to 4.2.1 & seems fine in the docs? |
@Johann-S: can't we make this a little less strict? |
I had the same issue. What I did to resolve it was looked over the code in the bootstrap.bundle.js from the 4.1.3 version, found the code that caused the issue in 4.2.1 and then replaced it. Basically in the 4.1.3 version, I went to line 141 which doesn't cause an error.
I then copied that version over to the 4.2.1 version and replaced it at line number 141. The code below is what causes the issue and needs to be replaced with the snippet above.
Just make sure to comment out the current code that you're replacing just in case it causes issues and test accordingly. This was a quick fix and while I checked for other references of the code usage, there's about 12 in the file, it didn't seem to break anything. Note: I haven't tested with other bootstrap features like the Carousel. So make sure to test it with the various features you implement. Hope this helps. |
Probably the same problem is occurring. Occurrence code.
|
My colleague hot-fixed this by adding data attribute Why is this starts working? There is no mention in the docs about any |
@mattez |
@mattez The error is:- |
A temporary fix would be to add a <a href="/profile" data-target="#" class="nav-link">Link</a> |
exactly @mattez but we plan to cut v4.3 in shorter time compared to v4.2 |
I'm having the same problem using the following code in ASP.NET:
When I jump to any link in a subfolder, the problem appears... DATA-TARGET did not solve it. Best regards |
Big porblem! in bootstrap 4.2.1 does NOT work in navbar dropdown menu if have link. in older version all work good. |
Just to let you know that since |
href="#" NOT fix, in Joomla very often required to make a parent menu item for a category, and required just need a link! not href="#" |
In this case use fix provided by @Johann-S, no big deal over here. |
@Homelux you should add a There is an example here: #27903 (comment) |
data-target for parent link or child link ? |
It depends which one trigger the dropdown |
@Johann-S THANK YOU!!! That fixed it for me. I had my menu set up like this, which was causing the error from above:
Essentially, I had to move the ID to the dropdown div, and reference it with data-target.
|
I have the same issue and I don't get the console error, when adding an unique id for the dropdown e.g. When I just set `href="#" it works, but it seems only to work with two levels (first level + dropdown). |
@bjarnef please open a new issue with a reduce test case (on CodePen or JSFiddle) it seems it's a different problem |
@Johann-S it is the same issue, but the "fix" with adding the id only open the dropdown, but doesn't close it on next click. Using href="#" works and open only child dropdown. When using the suggested solution with the id, it open also descendant menu levels. |
@bjarnef not totally because you're using multi dropdown level which isn't supported by Bootstrap |
@Johann-S yes, but it doesn't work with a single level either, when using the approach with an id, only when changing to Do you have an example (on CodePen or JSFiddle) with Bootstrap v4.2.1, where it close the dropdown after second click? |
I made one here: https://codepen.io/Johann-S/pen/WLaqQb?editors=1010 But I forget one thing, the see: <li id="parentDropdown" class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="/some-link" data-target="#parentDropdown" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li> |
@Johann-S , no one of the above solutions function with ASP.NET using Masterpage - and the 4.1.3 version was functioning very well. See the code below. It functions at the main page (the first page the website runs) but when I entry in a DropDown NAV-Item, the "selection function" really stops.
I tried all the above solutions and all of them I had the same behavior. Thank you for your attention. |
@Johann-S that seems to work. Unfortunately it only works with one level of dropdown. I was hoping Bootstrap 4 supported that, since it wasn't possible in Boostrap 3, where you had to handle this yourself. It seems you have do handle this in Boostrap 4 too something like this: I don't see the benefits of using the Boostrap dropdown component then, when you have to handle this part of the logic anyway. |
@DBenS I cannot help you more than that, if it works on your first page maybe there is something wrong on your other pages. Do not hesitate to ask around in the official Slack team or Stack Overflow. See our readme for more details. @bjarnef there is an issue open here : #27659 about multi level dropdown |
@Johann-S Thank you! Thanks! |
Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '/posts' is not a valid selector. twbs/bootstrap#27903 (comment)
The problem is that Dropdowns do not work in bootstrap 4.2 unless you have the javascript files at the bottom: <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script> |
Same for me DOMException: Failed to execute 'querySelector' on 'Document': '/recettes' is not a valid selector. O use in href="/recettes" for seo ... |
Found that making id's start with a non-numeric character solved the "document.querySelector failed to execute" issue I was getting. |
Remved for now twbs/bootstrap#27903
I'm having similar issue with 4.2.1 when adding Html.ActionLink, it causes the CSS/JS to break from the page. I'd appreciate a way to fix this. Note: If I added href="#" attribute, it wouldn't load the page and it would cause the link to become /# I'm getting the following error:
UPDATE: I was able to work around this error by adding attribute target-target="", allthought it copied the CCS styles of the div with id="navbarResponsive"
|
Updating your version of Bootstrap to the latest release will fix that (v4.3.1) |
Uh oh!
There was an error while loading. Please reload this page.
Bootstrap 4.2.1 / macOS 10.14.2 / Chrome 71.0.3578.98 / Safari 12.0.2
Dropdown works: https://codepen.io/anon/pen/oJZKXW
Dropdown doesn't work: https://codepen.io/anon/pen/BvWXNO
The problem arises due to the presence of the link.
In the application there are many places where the link in this place is “just like that”.
I think... it is necessary to fix it not on my side.
What do you think?
The text was updated successfully, but these errors were encountered: