1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-10 15:44:51 +02:00

fix(scrollspy): Spying on nested navs fails to activate for .nav-link's inside nav-item's (#23967)

* fix(scrollspy): Handle nested navs when nav-link inside nav-item

* [scrolspy] Find only child .nav-link's inside .nav-item

* [scrollspyt] Add tests for nested navs with nav-link inside nav-item

* fix troy-o's in test
This commit is contained in:
Troy Morehouse
2017-09-17 04:30:37 -03:00
committed by Johann-S
parent e296c13741
commit 6c70c70f63
2 changed files with 44 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ const ScrollSpy = (() => {
ACTIVE : '.active',
NAV_LIST_GROUP : '.nav, .list-group',
NAV_LINKS : '.nav-link',
NAV_ITEMS : '.nav-item',
LIST_ITEMS : '.list-group-item',
DROPDOWN : '.dropdown',
DROPDOWN_ITEMS : '.dropdown-item',
@@ -264,6 +265,8 @@ const ScrollSpy = (() => {
// Set triggered links parents as active
// With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor
$link.parents(Selector.NAV_LIST_GROUP).prev(`${Selector.NAV_LINKS}, ${Selector.LIST_ITEMS}`).addClass(ClassName.ACTIVE)
// Handle special case when .nav-link is inside .nav-item
$link.parents(Selector.NAV_LIST_GROUP).prev(Selector.NAV_ITEMS).children(Selector.NAV_LINKS).addClass(ClassName.ACTIVE)
}
$(this._scrollElement).trigger(Event.ACTIVATE, {