Skip to content

Commit

Permalink
fix(offcanas): activate focustrap when backdrop is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Jul 11, 2022
1 parent ac654a0 commit 9c966fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/src/offcanvas.js
Expand Up @@ -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()
}

Expand Down
24 changes: 23 additions & 1 deletion js/tests/unit/offcanvas.spec.js
Expand Up @@ -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()
Expand All @@ -306,6 +307,27 @@ describe('Offcanvas', () => {
offCanvas.show()
})
})

it('should trap focus if scroll is allowed & 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', () => {
Expand Down

0 comments on commit 9c966fd

Please sign in to comment.