Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2022-07-14 12:06:06 +0300
committerGitHub <noreply@github.com>2022-07-14 12:06:06 +0300
commit713d7140f18514c916f75be34e809ebe00c1691c (patch)
tree4b381784545f22a61f9c88ef15b52d32b515e029 /js
parent8bb68b04b35765c30038923bd620ee28b21553c8 (diff)
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>
Diffstat (limited to 'js')
-rw-r--r--js/src/offcanvas.js2
-rw-r--r--js/tests/unit/offcanvas.spec.js24
2 files changed, 24 insertions, 2 deletions
diff --git a/js/src/offcanvas.js b/js/src/offcanvas.js
index 34616eb37a..30a9a45136 100644
--- a/js/src/offcanvas.js
+++ b/js/src/offcanvas.js
@@ -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()
}
diff --git a/js/tests/unit/offcanvas.spec.js b/js/tests/unit/offcanvas.spec.js
index 3c862efca9..da2fb97480 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', () => {