mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
Extract Component config functionality to a separate class (#33872)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
+16
-11
@@ -7,7 +7,7 @@
|
||||
|
||||
import EventHandler from '../dom/event-handler'
|
||||
import SelectorEngine from '../dom/selector-engine'
|
||||
import { typeCheckConfig } from './index'
|
||||
import Config from './config'
|
||||
|
||||
/**
|
||||
* Constants
|
||||
@@ -37,13 +37,27 @@ const DefaultType = {
|
||||
* Class definition
|
||||
*/
|
||||
|
||||
class FocusTrap {
|
||||
class FocusTrap extends Config {
|
||||
constructor(config) {
|
||||
super()
|
||||
this._config = this._getConfig(config)
|
||||
this._isActive = false
|
||||
this._lastTabNavDirection = null
|
||||
}
|
||||
|
||||
// Getters
|
||||
static get Default() {
|
||||
return Default
|
||||
}
|
||||
|
||||
static get DefaultType() {
|
||||
return DefaultType
|
||||
}
|
||||
|
||||
static get NAME() {
|
||||
return NAME
|
||||
}
|
||||
|
||||
// Public
|
||||
activate() {
|
||||
const { trapElement, autofocus } = this._config
|
||||
@@ -99,15 +113,6 @@ class FocusTrap {
|
||||
|
||||
this._lastTabNavDirection = event.shiftKey ? TAB_NAV_BACKWARD : TAB_NAV_FORWARD
|
||||
}
|
||||
|
||||
_getConfig(config) {
|
||||
config = {
|
||||
...Default,
|
||||
...(typeof config === 'object' ? config : {})
|
||||
}
|
||||
typeCheckConfig(NAME, config, DefaultType)
|
||||
return config
|
||||
}
|
||||
}
|
||||
|
||||
export default FocusTrap
|
||||
|
||||
Reference in New Issue
Block a user