aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2022-07-14 12:06:06 +0300
committerGitHub <[email protected]>2022-07-14 10:06:06 +0100
commit713d7140f18514c916f75be34e809ebe00c1691c (patch)
tree4b381784545f22a61f9c88ef15b52d32b515e029 /js/tests/unit
parent8bb68b04b35765c30038923bd620ee28b21553c8 (diff)
downloadbootstrap-713d7140f18514c916f75be34e809ebe00c1691c.tar.xz
bootstrap-713d7140f18514c916f75be34e809ebe00c1691c.zip
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 <[email protected]> Co-authored-by: Julien Déramond <[email protected]> Co-authored-by: Patrick H. Lauke <[email protected]>
Diffstat (limited to 'js/tests/unit')
-rw-r--r--js/tests/unit/offcanvas.spec.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/js/tests/unit/offcanvas.spec.js b/js/tests/unit/offcanvas.spec.js
index 3c862efca..da2fb9748 100644
--- a/js/tests/unit/offcanvas.spec.js
+++ b/js/tests/unit/offcanvas.spec.js
@@ -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', () => {