mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-28 23:59:53 +02:00
Keep role="dialog"
after closing modal/offcanvas if already in the markup
This commit is contained in:
@@ -709,6 +709,35 @@ describe('Modal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should hide a modal and not remove role="dialog" if already present', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<div class="modal" role="dialog"><div class="modal-dialog"></div></div>'
|
||||
|
||||
const modalEl = fixtureEl.querySelector('.modal')
|
||||
const modal = new Modal(modalEl)
|
||||
const backdropSpy = spyOn(modal._backdrop, 'hide').and.callThrough()
|
||||
|
||||
modalEl.addEventListener('shown.bs.modal', () => {
|
||||
modal.hide()
|
||||
})
|
||||
|
||||
modalEl.addEventListener('hide.bs.modal', event => {
|
||||
expect(event).toBeDefined()
|
||||
})
|
||||
|
||||
modalEl.addEventListener('hidden.bs.modal', () => {
|
||||
expect(modalEl.getAttribute('aria-modal')).toBeNull()
|
||||
expect(modalEl.getAttribute('role')).toEqual('dialog')
|
||||
expect(modalEl.getAttribute('aria-hidden')).toEqual('true')
|
||||
expect(modalEl.style.display).toEqual('none')
|
||||
expect(backdropSpy).toHaveBeenCalled()
|
||||
resolve()
|
||||
})
|
||||
|
||||
modal.show()
|
||||
})
|
||||
})
|
||||
|
||||
it('should close modal when clicking outside of modal-content', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<div class="modal"><div class="modal-dialog"></div></div>'
|
||||
|
@@ -551,6 +551,26 @@ describe('Offcanvas', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should hide a shown element and not remove role="dialog" if already present', () => {
|
||||
return new Promise(resolve => {
|
||||
fixtureEl.innerHTML = '<div class="offcanvas" role="dialog"></div>'
|
||||
|
||||
const offCanvasEl = fixtureEl.querySelector('div')
|
||||
const offCanvas = new Offcanvas(offCanvasEl)
|
||||
const spy = spyOn(offCanvas._backdrop, 'hide').and.callThrough()
|
||||
offCanvas.show()
|
||||
|
||||
offCanvasEl.addEventListener('hidden.bs.offcanvas', () => {
|
||||
expect(offCanvasEl).not.toHaveClass('show')
|
||||
expect(offCanvasEl.getAttribute('role')).toEqual('dialog')
|
||||
expect(spy).toHaveBeenCalled()
|
||||
resolve()
|
||||
})
|
||||
|
||||
offCanvas.hide()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not fire hidden when hide is prevented', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
|
||||
|
Reference in New Issue
Block a user