mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 16:14:04 +02:00
Offcanvas.js: If scroll is allowed, should allow focus on other elements (#33677)
This commit is contained in:
@@ -112,6 +112,7 @@ class Offcanvas extends BaseComponent {
|
|||||||
|
|
||||||
if (!this._config.scroll) {
|
if (!this._config.scroll) {
|
||||||
scrollBarHide()
|
scrollBarHide()
|
||||||
|
this._enforceFocusOnElement(this._element)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._element.removeAttribute('aria-hidden')
|
this._element.removeAttribute('aria-hidden')
|
||||||
@@ -121,7 +122,6 @@ class Offcanvas extends BaseComponent {
|
|||||||
|
|
||||||
const completeCallBack = () => {
|
const completeCallBack = () => {
|
||||||
EventHandler.trigger(this._element, EVENT_SHOWN, { relatedTarget })
|
EventHandler.trigger(this._element, EVENT_SHOWN, { relatedTarget })
|
||||||
this._enforceFocusOnElement(this._element)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const transitionDuration = getTransitionDurationFromElement(this._element)
|
const transitionDuration = getTransitionDurationFromElement(this._element)
|
||||||
|
@@ -220,6 +220,24 @@ describe('Offcanvas', () => {
|
|||||||
|
|
||||||
offCanvas.show()
|
offCanvas.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not enforce focus if focus scroll is allowed', done => {
|
||||||
|
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
|
||||||
|
|
||||||
|
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
|
||||||
|
const offCanvas = new Offcanvas(offCanvasEl, {
|
||||||
|
scroll: true
|
||||||
|
})
|
||||||
|
|
||||||
|
spyOn(offCanvas, '_enforceFocusOnElement')
|
||||||
|
|
||||||
|
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
||||||
|
expect(offCanvas._enforceFocusOnElement).not.toHaveBeenCalled()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
offCanvas.show()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('toggle', () => {
|
describe('toggle', () => {
|
||||||
@@ -328,6 +346,22 @@ describe('Offcanvas', () => {
|
|||||||
expect(instance).not.toBeNull()
|
expect(instance).not.toBeNull()
|
||||||
expect(Offcanvas.prototype.show).toHaveBeenCalled()
|
expect(Offcanvas.prototype.show).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should enforce focus', done => {
|
||||||
|
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
|
||||||
|
|
||||||
|
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
|
||||||
|
const offCanvas = new Offcanvas(offCanvasEl)
|
||||||
|
|
||||||
|
spyOn(offCanvas, '_enforceFocusOnElement')
|
||||||
|
|
||||||
|
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
|
||||||
|
expect(offCanvas._enforceFocusOnElement).toHaveBeenCalled()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
offCanvas.show()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('hide', () => {
|
describe('hide', () => {
|
||||||
|
Reference in New Issue
Block a user