aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/offcanvas.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/offcanvas.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/offcanvas.js36
1 files changed, 17 insertions, 19 deletions
diff --git a/vendor/twbs/bootstrap/js/src/offcanvas.js b/vendor/twbs/bootstrap/js/src/offcanvas.js
index 88eb8c997..66378fd23 100644
--- a/vendor/twbs/bootstrap/js/src/offcanvas.js
+++ b/vendor/twbs/bootstrap/js/src/offcanvas.js
@@ -1,7 +1,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): offcanvas.js
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ * Bootstrap (v5.1.3): offcanvas.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -18,6 +18,8 @@ import BaseComponent from './base-component'
import SelectorEngine from './dom/selector-engine'
import Manipulator from './dom/manipulator'
import Backdrop from './util/backdrop'
+import FocusTrap from './util/focustrap'
+import { enableDismissTrigger } from './util/component-functions'
/**
* ------------------------------------------------------------------------
@@ -45,18 +47,16 @@ const DefaultType = {
}
const CLASS_NAME_SHOW = 'show'
+const CLASS_NAME_BACKDROP = 'offcanvas-backdrop'
const OPEN_SELECTOR = '.offcanvas.show'
const EVENT_SHOW = `show${EVENT_KEY}`
const EVENT_SHOWN = `shown${EVENT_KEY}`
const EVENT_HIDE = `hide${EVENT_KEY}`
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
-const EVENT_FOCUSIN = `focusin${EVENT_KEY}`
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
-const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
-const SELECTOR_DATA_DISMISS = '[data-bs-dismiss="offcanvas"]'
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="offcanvas"]'
/**
@@ -72,6 +72,7 @@ class Offcanvas extends BaseComponent {
this._config = this._getConfig(config)
this._isShown = false
this._backdrop = this._initializeBackDrop()
+ this._focustrap = this._initializeFocusTrap()
this._addEventListeners()
}
@@ -109,7 +110,6 @@ class Offcanvas extends BaseComponent {
if (!this._config.scroll) {
new ScrollBarHelper().hide()
- this._enforceFocusOnElement(this._element)
}
this._element.removeAttribute('aria-hidden')
@@ -118,6 +118,10 @@ class Offcanvas extends BaseComponent {
this._element.classList.add(CLASS_NAME_SHOW)
const completeCallBack = () => {
+ if (!this._config.scroll) {
+ this._focustrap.activate()
+ }
+
EventHandler.trigger(this._element, EVENT_SHOWN, { relatedTarget })
}
@@ -135,7 +139,7 @@ class Offcanvas extends BaseComponent {
return
}
- EventHandler.off(document, EVENT_FOCUSIN)
+ this._focustrap.deactivate()
this._element.blur()
this._isShown = false
this._element.classList.remove(CLASS_NAME_SHOW)
@@ -159,8 +163,8 @@ class Offcanvas extends BaseComponent {
dispose() {
this._backdrop.dispose()
+ this._focustrap.deactivate()
super.dispose()
- EventHandler.off(document, EVENT_FOCUSIN)
}
// Private
@@ -177,6 +181,7 @@ class Offcanvas extends BaseComponent {
_initializeBackDrop() {
return new Backdrop({
+ className: CLASS_NAME_BACKDROP,
isVisible: this._config.backdrop,
isAnimated: true,
rootElement: this._element.parentNode,
@@ -184,21 +189,13 @@ class Offcanvas extends BaseComponent {
})
}
- _enforceFocusOnElement(element) {
- EventHandler.off(document, EVENT_FOCUSIN) // guard against infinite focus loop
- EventHandler.on(document, EVENT_FOCUSIN, event => {
- if (document !== event.target &&
- element !== event.target &&
- !element.contains(event.target)) {
- element.focus()
- }
+ _initializeFocusTrap() {
+ return new FocusTrap({
+ trapElement: this._element
})
- element.focus()
}
_addEventListeners() {
- EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide())
-
EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
if (this._config.keyboard && event.key === ESCAPE_KEY) {
this.hide()
@@ -263,6 +260,7 @@ EventHandler.on(window, EVENT_LOAD_DATA_API, () =>
SelectorEngine.find(OPEN_SELECTOR).forEach(el => Offcanvas.getOrCreateInstance(el).show())
)
+enableDismissTrigger(Offcanvas)
/**
* ------------------------------------------------------------------------
* jQuery