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.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/vendor/twbs/bootstrap/js/src/offcanvas.js b/vendor/twbs/bootstrap/js/src/offcanvas.js
index 57bf2e897..88eb8c997 100644
--- a/vendor/twbs/bootstrap/js/src/offcanvas.js
+++ b/vendor/twbs/bootstrap/js/src/offcanvas.js
@@ -1,6 +1,6 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.1.1): offcanvas.js
+ * Bootstrap (v5.0.2): offcanvas.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -18,8 +18,6 @@ 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'
/**
* ------------------------------------------------------------------------
@@ -47,16 +45,18 @@ 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,7 +72,6 @@ class Offcanvas extends BaseComponent {
this._config = this._getConfig(config)
this._isShown = false
this._backdrop = this._initializeBackDrop()
- this._focustrap = this._initializeFocusTrap()
this._addEventListeners()
}
@@ -110,6 +109,7 @@ class Offcanvas extends BaseComponent {
if (!this._config.scroll) {
new ScrollBarHelper().hide()
+ this._enforceFocusOnElement(this._element)
}
this._element.removeAttribute('aria-hidden')
@@ -118,10 +118,6 @@ 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 })
}
@@ -139,7 +135,7 @@ class Offcanvas extends BaseComponent {
return
}
- this._focustrap.deactivate()
+ EventHandler.off(document, EVENT_FOCUSIN)
this._element.blur()
this._isShown = false
this._element.classList.remove(CLASS_NAME_SHOW)
@@ -163,8 +159,8 @@ class Offcanvas extends BaseComponent {
dispose() {
this._backdrop.dispose()
- this._focustrap.deactivate()
super.dispose()
+ EventHandler.off(document, EVENT_FOCUSIN)
}
// Private
@@ -181,7 +177,6 @@ class Offcanvas extends BaseComponent {
_initializeBackDrop() {
return new Backdrop({
- className: CLASS_NAME_BACKDROP,
isVisible: this._config.backdrop,
isAnimated: true,
rootElement: this._element.parentNode,
@@ -189,13 +184,21 @@ class Offcanvas extends BaseComponent {
})
}
- _initializeFocusTrap() {
- return new FocusTrap({
- trapElement: this._element
+ _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()
+ }
})
+ 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()
@@ -260,7 +263,6 @@ EventHandler.on(window, EVENT_LOAD_DATA_API, () =>
SelectorEngine.find(OPEN_SELECTOR).forEach(el => Offcanvas.getOrCreateInstance(el).show())
)
-enableDismissTrigger(Offcanvas)
/**
* ------------------------------------------------------------------------
* jQuery