Skip to content

Commit

Permalink
Fix: Error is thrown when menu item can not be found
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyvgy committed Feb 17, 2019
1 parent 34b0e86 commit cc01244
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ export class ScrollSpy {
const section = this.getSectionInView()
const menuItem = this.getMenuItemBySection(section)

this.removeCurrentActive({ ignore: menuItem })
this.setActive(menuItem)
if (menuItem) {
this.removeCurrentActive({ ignore: menuItem })
this.setActive(menuItem)
}
}

getMenuItemBySection(section) {
if (!section) return
const sectionId = section.getAttribute('id')
return this.menuList.querySelector(`[${this.options.hrefAttribute}="#${sectionId}"]`)
}
Expand Down

0 comments on commit cc01244

Please sign in to comment.