Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ScrollSpy extends BaseComponent {
EventHandler.off(this._config.target, EVENT_CLICK)

EventHandler.on(this._config.target, EVENT_CLICK, SELECTOR_TARGET_LINKS, event => {
const observableSection = this._observableSections.get(event.target.hash)
const observableSection = this._observableSections.get(event.delegateTarget.hash)
if (observableSection) {
event.preventDefault()
const root = this._rootElement || window
Expand Down
18 changes: 18 additions & 0 deletions js/tests/unit/scrollspy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,24 @@ describe('ScrollSpy', () => {
link.click()
})

it('should smoothScroll when clicking an element nested in an anchor', () => {
fixtureEl.innerHTML = getDummyFixture()

const div = fixtureEl.querySelector('.content')
const link = fixtureEl.querySelector('[href="#div-jsm-1"]')
const observable = fixtureEl.querySelector('#div-jsm-1')
const clickSpy = getElementScrollSpy(div)
link.innerHTML = '<span>div 1</span>'
// eslint-disable-next-line no-new
new ScrollSpy(div, {
offset: 1,
smoothScroll: true
})

link.querySelector('span').click()
expect(clickSpy).toHaveBeenCalledWith({ top: observable.offsetTop - div.offsetTop, behavior: 'smooth' })
})

it('should smoothscroll to observable with anchor link that contains a french word as id', done => {
fixtureEl.innerHTML = [
'<nav id="navBar" class="navbar">',
Expand Down