1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-05 13:17:32 +02:00

Offcanvas: activate focustrap when backdrop is enabled (#36717)

* fix(offcanvas): activate focustrap when backdrop is enabled
* Adding tabindex='-1' for both offcanvases in the docs
* Remove useless aria-expanded='false' in togglers
* Update js/tests/unit/offcanvas.spec.js

Co-authored-by: Julien Déramond <julien.deramond@orange.com>
Co-authored-by: Julien Déramond <juderamond@gmail.com>
Co-authored-by: Patrick H. Lauke <redux@splintered.co.uk>
This commit is contained in:
GeoSot
2022-07-14 12:06:06 +03:00
committed by GitHub
parent 8bb68b04b3
commit 713d7140f1
4 changed files with 28 additions and 6 deletions

View File

@@ -114,7 +114,7 @@ class Offcanvas extends BaseComponent {
this._element.classList.add(CLASS_NAME_SHOWING)
const completeCallBack = () => {
if (!this._config.scroll) {
if (!this._config.scroll || this._config.backdrop) {
this._focustrap.activate()
}

View File

@@ -293,7 +293,8 @@ describe('Offcanvas', () => {
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl, {
scroll: true
scroll: true,
backdrop: false
})
const spy = spyOn(offCanvas._focustrap, 'activate').and.callThrough()
@@ -306,6 +307,27 @@ describe('Offcanvas', () => {
offCanvas.show()
})
})
it('should trap focus if scroll is allowed OR backdrop is enabled', () => {
return new Promise(resolve => {
fixtureEl.innerHTML = '<div class="offcanvas"></div>'
const offCanvasEl = fixtureEl.querySelector('.offcanvas')
const offCanvas = new Offcanvas(offCanvasEl, {
scroll: true,
backdrop: true
})
const spy = spyOn(offCanvas._focustrap, 'activate').and.callThrough()
offCanvasEl.addEventListener('shown.bs.offcanvas', () => {
expect(spy).toHaveBeenCalled()
resolve()
})
offCanvas.show()
})
})
})
describe('toggle', () => {