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

Collapse: Fix multiple ids calls #38989

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions js/src/dom/selector-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const getSelector = element => {
hrefAttribute = `#${hrefAttribute.split('#')[1]}`
}

selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null
selector = hrefAttribute && hrefAttribute !== '#' ? parseSelector(hrefAttribute.trim()) : null
}

return parseSelector(selector)
return selector
}

const SelectorEngine = {
Expand Down
12 changes: 12 additions & 0 deletions js/tests/unit/dom/selector-engine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ describe('SelectorEngine', () => {
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
})

it('should get elements if several ids are given', () => {
fixtureEl.innerHTML = [
'<div id="test" data-bs-target="#target1,#target2"></div>',
'<div class="target" id="target1"></div>',
'<div class="target" id="target2"></div>'
].join('')

const testEl = fixtureEl.querySelector('#test')

expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
})

it('should get elements in array, from href if no data-bs-target set', () => {
fixtureEl.innerHTML = [
'<a id="test" href=".target"></a>',
Expand Down