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

Chore merge from d30385b to c396a2a #2482

Merged
merged 10 commits into from
Feb 19, 2024
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 !== '#' ? parseSelector(hrefAttribute.trim()) : null
selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null
}

return selector
return selector ? selector.split(',').map(sel => parseSelector(sel)).join(',') : null
}

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 @@ -371,6 +371,18 @@ describe('SelectorEngine', () => {
expect(SelectorEngine.getMultipleElementsFromSelector(testEl)).toEqual(Array.from(fixtureEl.querySelectorAll('.target')))
})

it('should get elements if several ids with special chars are given', () => {
fixtureEl.innerHTML = [
'<div id="test" data-bs-target="#j_id11:exampleModal,#j_id22:exampleModal"></div>',
'<div class="target" id="j_id11:exampleModal"></div>',
'<div class="target" id="j_id22:exampleModal"></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
29 changes: 29 additions & 0 deletions js/tests/unit/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,35 @@ describe('Modal', () => {
trigger.click()
})
})

it('should open modal, having special characters in its id', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
'<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#j_id22:exampleModal">',
' Launch demo modal',
'</button>',
'<div class="modal fade" id="j_id22:exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">',
' <div class="modal-dialog">',
' <div class="modal-content">',
' <div class="modal-body">',
' <p>modal body</p>',
' </div>',
' </div>',
' </div>',
'</div>'
].join('')

const modalEl = fixtureEl.querySelector('.modal')
const trigger = fixtureEl.querySelector('[data-bs-toggle="modal"]')

modalEl.addEventListener('shown.bs.modal', () => {
resolve()
})

trigger.click()
})
})

it('should not prevent default when a click occurred on data-bs-dismiss="modal" where tagName is DIFFERENT than <a> or <area>', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = [
Expand Down
Loading
Loading