bootstrap 5.2.3 → 5.3.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/assets/javascripts/bootstrap/alert.js +21 -32
- data/assets/javascripts/bootstrap/base-component.js +21 -38
- data/assets/javascripts/bootstrap/button.js +18 -22
- data/assets/javascripts/bootstrap/carousel.js +51 -135
- data/assets/javascripts/bootstrap/collapse.js +39 -102
- data/assets/javascripts/bootstrap/dom/data.js +8 -12
- data/assets/javascripts/bootstrap/dom/event-handler.js +18 -66
- data/assets/javascripts/bootstrap/dom/manipulator.js +4 -17
- data/assets/javascripts/bootstrap/dom/selector-engine.js +41 -24
- data/assets/javascripts/bootstrap/dropdown.js +73 -145
- data/assets/javascripts/bootstrap/modal.js +52 -133
- data/assets/javascripts/bootstrap/offcanvas.js +49 -102
- data/assets/javascripts/bootstrap/popover.js +22 -29
- data/assets/javascripts/bootstrap/scrollspy.js +51 -89
- data/assets/javascripts/bootstrap/tab.js +51 -109
- data/assets/javascripts/bootstrap/toast.js +30 -73
- data/assets/javascripts/bootstrap/tooltip.js +74 -177
- data/assets/javascripts/bootstrap/util/backdrop.js +27 -54
- data/assets/javascripts/bootstrap/util/component-functions.js +13 -19
- data/assets/javascripts/bootstrap/util/config.js +14 -27
- data/assets/javascripts/bootstrap/util/focustrap.js +19 -36
- data/assets/javascripts/bootstrap/util/index.js +42 -111
- data/assets/javascripts/bootstrap/util/sanitizer.js +13 -19
- data/assets/javascripts/bootstrap/util/scrollbar.js +23 -50
- data/assets/javascripts/bootstrap/util/swipe.js +26 -48
- data/assets/javascripts/bootstrap/util/template-factory.js +24 -52
- data/assets/javascripts/bootstrap-sprockets.js +1 -1
- data/assets/javascripts/bootstrap.js +626 -1406
- data/assets/javascripts/bootstrap.min.js +3 -3
- data/assets/stylesheets/_bootstrap-grid.scss +1 -3
- data/assets/stylesheets/_bootstrap-reboot.scss +1 -0
- data/assets/stylesheets/_bootstrap.scss +1 -0
- data/assets/stylesheets/bootstrap/_accordion.scss +9 -0
- data/assets/stylesheets/bootstrap/_alert.scss +8 -11
- data/assets/stylesheets/bootstrap/_button-group.scss +2 -2
- data/assets/stylesheets/bootstrap/_buttons.scss +3 -3
- data/assets/stylesheets/bootstrap/_card.scss +5 -0
- data/assets/stylesheets/bootstrap/_carousel.scss +20 -2
- data/assets/stylesheets/bootstrap/_close.scss +32 -9
- data/assets/stylesheets/bootstrap/_dropdown.scss +1 -0
- data/assets/stylesheets/bootstrap/_functions.scss +1 -1
- data/assets/stylesheets/bootstrap/_grid.scss +6 -0
- data/assets/stylesheets/bootstrap/_helpers.scss +2 -0
- data/assets/stylesheets/bootstrap/_list-group.scss +12 -7
- data/assets/stylesheets/bootstrap/_maps.scss +120 -0
- data/assets/stylesheets/bootstrap/_mixins.scss +1 -2
- data/assets/stylesheets/bootstrap/_nav.scss +40 -3
- data/assets/stylesheets/bootstrap/_navbar.scss +13 -3
- data/assets/stylesheets/bootstrap/_offcanvas.scss +4 -2
- data/assets/stylesheets/bootstrap/_pagination.scss +1 -1
- data/assets/stylesheets/bootstrap/_progress.scss +10 -1
- data/assets/stylesheets/bootstrap/_reboot.scss +3 -3
- data/assets/stylesheets/bootstrap/_root.scss +125 -10
- data/assets/stylesheets/bootstrap/_tables.scss +1 -1
- data/assets/stylesheets/bootstrap/_tooltip.scss +4 -5
- data/assets/stylesheets/bootstrap/_utilities.scss +172 -13
- data/assets/stylesheets/bootstrap/_variables-dark.scss +85 -0
- data/assets/stylesheets/bootstrap/_variables.scss +260 -151
- data/assets/stylesheets/bootstrap/bootstrap-utilities.scss +1 -0
- data/assets/stylesheets/bootstrap/forms/_floating-labels.scss +21 -3
- data/assets/stylesheets/bootstrap/forms/_form-check.scss +24 -11
- data/assets/stylesheets/bootstrap/forms/_form-control.scss +23 -3
- data/assets/stylesheets/bootstrap/forms/_form-select.scss +11 -2
- data/assets/stylesheets/bootstrap/forms/_input-group.scss +1 -1
- data/assets/stylesheets/bootstrap/helpers/_colored-links.scss +22 -2
- data/assets/stylesheets/bootstrap/helpers/_focus-ring.scss +5 -0
- data/assets/stylesheets/bootstrap/helpers/_icon-link.scss +25 -0
- data/assets/stylesheets/bootstrap/mixins/_alert.scss +4 -1
- data/assets/stylesheets/bootstrap/mixins/_banner.scss +2 -4
- data/assets/stylesheets/bootstrap/mixins/_caret.scss +30 -25
- data/assets/stylesheets/bootstrap/mixins/_color-mode.scss +21 -0
- data/assets/stylesheets/bootstrap/mixins/_forms.scss +8 -7
- data/assets/stylesheets/bootstrap/mixins/_list-group.scss +2 -0
- data/assets/stylesheets/bootstrap/mixins/_utilities.scss +1 -1
- data/assets/stylesheets/bootstrap/mixins/_visually-hidden.scss +5 -1
- data/assets/stylesheets/bootstrap/vendor/_rfs.scss +23 -29
- data/bootstrap.gemspec +1 -1
- data/lib/bootstrap/version.rb +2 -2
- data/tasks/updater/js.rb +1 -1
- data/tasks/updater/scss.rb +1 -1
- metadata +10 -6
@@ -1,25 +1,21 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap backdrop.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap backdrop.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/event-handler'), require('./
|
8
|
-
typeof define === 'function' && define.amd ? define(['../dom/event-handler', './
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Backdrop = factory(global.EventHandler, global.
|
10
|
-
})(this, (function (EventHandler,
|
11
|
-
|
12
|
-
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
13
|
-
|
14
|
-
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
15
|
-
const Config__default = /*#__PURE__*/_interopDefaultLegacy(Config);
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/event-handler.js'), require('./config.js'), require('./index.js')) :
|
8
|
+
typeof define === 'function' && define.amd ? define(['../dom/event-handler', './config', './index'], factory) :
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Backdrop = factory(global.EventHandler, global.Config, global.Index));
|
10
|
+
})(this, (function (EventHandler, Config, index_js) { 'use strict';
|
16
11
|
|
17
12
|
/**
|
18
13
|
* --------------------------------------------------------------------------
|
19
|
-
* Bootstrap
|
14
|
+
* Bootstrap util/backdrop.js
|
20
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
21
16
|
* --------------------------------------------------------------------------
|
22
17
|
*/
|
18
|
+
|
23
19
|
/**
|
24
20
|
* Constants
|
25
21
|
*/
|
@@ -35,8 +31,8 @@
|
|
35
31
|
isVisible: true,
|
36
32
|
// if false, we use the backdrop helper without adding any element to the dom
|
37
33
|
rootElement: 'body' // give the choice to place backdrop under different elements
|
38
|
-
|
39
34
|
};
|
35
|
+
|
40
36
|
const DefaultType = {
|
41
37
|
className: 'string',
|
42
38
|
clickCallback: '(function|null)',
|
@@ -44,120 +40,97 @@
|
|
44
40
|
isVisible: 'boolean',
|
45
41
|
rootElement: '(element|string)'
|
46
42
|
};
|
43
|
+
|
47
44
|
/**
|
48
45
|
* Class definition
|
49
46
|
*/
|
50
47
|
|
51
|
-
class Backdrop extends
|
48
|
+
class Backdrop extends Config {
|
52
49
|
constructor(config) {
|
53
50
|
super();
|
54
51
|
this._config = this._getConfig(config);
|
55
52
|
this._isAppended = false;
|
56
53
|
this._element = null;
|
57
|
-
}
|
58
|
-
|
54
|
+
}
|
59
55
|
|
56
|
+
// Getters
|
60
57
|
static get Default() {
|
61
58
|
return Default;
|
62
59
|
}
|
63
|
-
|
64
60
|
static get DefaultType() {
|
65
61
|
return DefaultType;
|
66
62
|
}
|
67
|
-
|
68
63
|
static get NAME() {
|
69
64
|
return NAME;
|
70
|
-
}
|
71
|
-
|
65
|
+
}
|
72
66
|
|
67
|
+
// Public
|
73
68
|
show(callback) {
|
74
69
|
if (!this._config.isVisible) {
|
75
|
-
|
70
|
+
index_js.execute(callback);
|
76
71
|
return;
|
77
72
|
}
|
78
|
-
|
79
73
|
this._append();
|
80
|
-
|
81
74
|
const element = this._getElement();
|
82
|
-
|
83
75
|
if (this._config.isAnimated) {
|
84
|
-
|
76
|
+
index_js.reflow(element);
|
85
77
|
}
|
86
|
-
|
87
78
|
element.classList.add(CLASS_NAME_SHOW);
|
88
|
-
|
89
79
|
this._emulateAnimation(() => {
|
90
|
-
|
80
|
+
index_js.execute(callback);
|
91
81
|
});
|
92
82
|
}
|
93
|
-
|
94
83
|
hide(callback) {
|
95
84
|
if (!this._config.isVisible) {
|
96
|
-
|
85
|
+
index_js.execute(callback);
|
97
86
|
return;
|
98
87
|
}
|
99
|
-
|
100
88
|
this._getElement().classList.remove(CLASS_NAME_SHOW);
|
101
|
-
|
102
89
|
this._emulateAnimation(() => {
|
103
90
|
this.dispose();
|
104
|
-
|
91
|
+
index_js.execute(callback);
|
105
92
|
});
|
106
93
|
}
|
107
|
-
|
108
94
|
dispose() {
|
109
95
|
if (!this._isAppended) {
|
110
96
|
return;
|
111
97
|
}
|
112
|
-
|
113
|
-
EventHandler__default.default.off(this._element, EVENT_MOUSEDOWN);
|
114
|
-
|
98
|
+
EventHandler.off(this._element, EVENT_MOUSEDOWN);
|
115
99
|
this._element.remove();
|
116
|
-
|
117
100
|
this._isAppended = false;
|
118
|
-
}
|
119
|
-
|
101
|
+
}
|
120
102
|
|
103
|
+
// Private
|
121
104
|
_getElement() {
|
122
105
|
if (!this._element) {
|
123
106
|
const backdrop = document.createElement('div');
|
124
107
|
backdrop.className = this._config.className;
|
125
|
-
|
126
108
|
if (this._config.isAnimated) {
|
127
109
|
backdrop.classList.add(CLASS_NAME_FADE);
|
128
110
|
}
|
129
|
-
|
130
111
|
this._element = backdrop;
|
131
112
|
}
|
132
|
-
|
133
113
|
return this._element;
|
134
114
|
}
|
135
|
-
|
136
115
|
_configAfterMerge(config) {
|
137
116
|
// use getElement() with the default "body" to get a fresh Element on each instantiation
|
138
|
-
config.rootElement =
|
117
|
+
config.rootElement = index_js.getElement(config.rootElement);
|
139
118
|
return config;
|
140
119
|
}
|
141
|
-
|
142
120
|
_append() {
|
143
121
|
if (this._isAppended) {
|
144
122
|
return;
|
145
123
|
}
|
146
|
-
|
147
124
|
const element = this._getElement();
|
148
|
-
|
149
125
|
this._config.rootElement.append(element);
|
150
|
-
|
151
|
-
|
152
|
-
index.execute(this._config.clickCallback);
|
126
|
+
EventHandler.on(element, EVENT_MOUSEDOWN, () => {
|
127
|
+
index_js.execute(this._config.clickCallback);
|
153
128
|
});
|
154
129
|
this._isAppended = true;
|
155
130
|
}
|
156
|
-
|
157
131
|
_emulateAnimation(callback) {
|
158
|
-
|
132
|
+
index_js.executeAfterTransition(callback, this._getElement(), this._config.isAnimated);
|
159
133
|
}
|
160
|
-
|
161
134
|
}
|
162
135
|
|
163
136
|
return Backdrop;
|
@@ -1,46 +1,40 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap component-functions.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap component-functions.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('../dom/event-handler'), require('./index')) :
|
8
|
-
typeof define === 'function' && define.amd ? define(['exports', '../dom/event-handler', './index'], factory) :
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComponentFunctions = {}, global.EventHandler, global.Index));
|
10
|
-
})(this, (function (exports, EventHandler,
|
11
|
-
|
12
|
-
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
13
|
-
|
14
|
-
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('../dom/event-handler.js'), require('../dom/selector-engine.js'), require('./index.js')) :
|
8
|
+
typeof define === 'function' && define.amd ? define(['exports', '../dom/event-handler', '../dom/selector-engine', './index'], factory) :
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComponentFunctions = {}, global.EventHandler, global.SelectorEngine, global.Index));
|
10
|
+
})(this, (function (exports, EventHandler, SelectorEngine, index_js) { 'use strict';
|
15
11
|
|
16
12
|
/**
|
17
13
|
* --------------------------------------------------------------------------
|
18
|
-
* Bootstrap
|
14
|
+
* Bootstrap util/component-functions.js
|
19
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
20
16
|
* --------------------------------------------------------------------------
|
21
17
|
*/
|
22
|
-
|
23
18
|
const enableDismissTrigger = (component, method = 'hide') => {
|
24
19
|
const clickEvent = `click.dismiss${component.EVENT_KEY}`;
|
25
20
|
const name = component.NAME;
|
26
|
-
|
21
|
+
EventHandler.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
|
27
22
|
if (['A', 'AREA'].includes(this.tagName)) {
|
28
23
|
event.preventDefault();
|
29
24
|
}
|
30
|
-
|
31
|
-
if (index.isDisabled(this)) {
|
25
|
+
if (index_js.isDisabled(this)) {
|
32
26
|
return;
|
33
27
|
}
|
28
|
+
const target = SelectorEngine.getElementFromSelector(this) || this.closest(`.${name}`);
|
29
|
+
const instance = component.getOrCreateInstance(target);
|
34
30
|
|
35
|
-
|
36
|
-
const instance = component.getOrCreateInstance(target); // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
|
37
|
-
|
31
|
+
// Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
|
38
32
|
instance[method]();
|
39
33
|
});
|
40
34
|
};
|
41
35
|
|
42
36
|
exports.enableDismissTrigger = enableDismissTrigger;
|
43
37
|
|
44
|
-
Object.
|
38
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
45
39
|
|
46
40
|
}));
|
@@ -1,24 +1,21 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap config.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap config.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('
|
8
|
-
typeof define === 'function' && define.amd ? define(['
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Config = factory(global.
|
10
|
-
})(this, (function (
|
11
|
-
|
12
|
-
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
13
|
-
|
14
|
-
const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/manipulator.js'), require('./index.js')) :
|
8
|
+
typeof define === 'function' && define.amd ? define(['../dom/manipulator', './index'], factory) :
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Config = factory(global.Manipulator, global.Index));
|
10
|
+
})(this, (function (Manipulator, index_js) { 'use strict';
|
15
11
|
|
16
12
|
/**
|
17
13
|
* --------------------------------------------------------------------------
|
18
|
-
* Bootstrap
|
14
|
+
* Bootstrap util/config.js
|
19
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
20
16
|
* --------------------------------------------------------------------------
|
21
17
|
*/
|
18
|
+
|
22
19
|
/**
|
23
20
|
* Class definition
|
24
21
|
*/
|
@@ -28,50 +25,40 @@
|
|
28
25
|
static get Default() {
|
29
26
|
return {};
|
30
27
|
}
|
31
|
-
|
32
28
|
static get DefaultType() {
|
33
29
|
return {};
|
34
30
|
}
|
35
|
-
|
36
31
|
static get NAME() {
|
37
32
|
throw new Error('You have to implement the static method "NAME", for each component!');
|
38
33
|
}
|
39
|
-
|
40
34
|
_getConfig(config) {
|
41
35
|
config = this._mergeConfigObj(config);
|
42
36
|
config = this._configAfterMerge(config);
|
43
|
-
|
44
37
|
this._typeCheckConfig(config);
|
45
|
-
|
46
38
|
return config;
|
47
39
|
}
|
48
|
-
|
49
40
|
_configAfterMerge(config) {
|
50
41
|
return config;
|
51
42
|
}
|
52
|
-
|
53
43
|
_mergeConfigObj(config, element) {
|
54
|
-
const jsonConfig =
|
44
|
+
const jsonConfig = index_js.isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {}; // try to parse
|
55
45
|
|
56
|
-
return {
|
46
|
+
return {
|
47
|
+
...this.constructor.Default,
|
57
48
|
...(typeof jsonConfig === 'object' ? jsonConfig : {}),
|
58
|
-
...(
|
49
|
+
...(index_js.isElement(element) ? Manipulator.getDataAttributes(element) : {}),
|
59
50
|
...(typeof config === 'object' ? config : {})
|
60
51
|
};
|
61
52
|
}
|
62
|
-
|
63
53
|
_typeCheckConfig(config, configTypes = this.constructor.DefaultType) {
|
64
|
-
for (const property of Object.
|
65
|
-
const expectedTypes = configTypes[property];
|
54
|
+
for (const [property, expectedTypes] of Object.entries(configTypes)) {
|
66
55
|
const value = config[property];
|
67
|
-
const valueType =
|
68
|
-
|
56
|
+
const valueType = index_js.isElement(value) ? 'element' : index_js.toType(value);
|
69
57
|
if (!new RegExp(expectedTypes).test(valueType)) {
|
70
58
|
throw new TypeError(`${this.constructor.NAME.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
|
71
59
|
}
|
72
60
|
}
|
73
61
|
}
|
74
|
-
|
75
62
|
}
|
76
63
|
|
77
64
|
return Config;
|
@@ -1,26 +1,21 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap focustrap.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap focustrap.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/event-handler'), require('../dom/selector-engine'), require('./config')) :
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/event-handler.js'), require('../dom/selector-engine.js'), require('./config.js')) :
|
8
8
|
typeof define === 'function' && define.amd ? define(['../dom/event-handler', '../dom/selector-engine', './config'], factory) :
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Focustrap = factory(global.EventHandler, global.SelectorEngine, global.Config));
|
10
10
|
})(this, (function (EventHandler, SelectorEngine, Config) { 'use strict';
|
11
11
|
|
12
|
-
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
13
|
-
|
14
|
-
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
15
|
-
const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
16
|
-
const Config__default = /*#__PURE__*/_interopDefaultLegacy(Config);
|
17
|
-
|
18
12
|
/**
|
19
13
|
* --------------------------------------------------------------------------
|
20
|
-
* Bootstrap
|
14
|
+
* Bootstrap util/focustrap.js
|
21
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
22
16
|
* --------------------------------------------------------------------------
|
23
17
|
*/
|
18
|
+
|
24
19
|
/**
|
25
20
|
* Constants
|
26
21
|
*/
|
@@ -36,75 +31,66 @@
|
|
36
31
|
const Default = {
|
37
32
|
autofocus: true,
|
38
33
|
trapElement: null // The element to trap focus inside of
|
39
|
-
|
40
34
|
};
|
35
|
+
|
41
36
|
const DefaultType = {
|
42
37
|
autofocus: 'boolean',
|
43
38
|
trapElement: 'element'
|
44
39
|
};
|
40
|
+
|
45
41
|
/**
|
46
42
|
* Class definition
|
47
43
|
*/
|
48
44
|
|
49
|
-
class FocusTrap extends
|
45
|
+
class FocusTrap extends Config {
|
50
46
|
constructor(config) {
|
51
47
|
super();
|
52
48
|
this._config = this._getConfig(config);
|
53
49
|
this._isActive = false;
|
54
50
|
this._lastTabNavDirection = null;
|
55
|
-
}
|
56
|
-
|
51
|
+
}
|
57
52
|
|
53
|
+
// Getters
|
58
54
|
static get Default() {
|
59
55
|
return Default;
|
60
56
|
}
|
61
|
-
|
62
57
|
static get DefaultType() {
|
63
58
|
return DefaultType;
|
64
59
|
}
|
65
|
-
|
66
60
|
static get NAME() {
|
67
61
|
return NAME;
|
68
|
-
}
|
69
|
-
|
62
|
+
}
|
70
63
|
|
64
|
+
// Public
|
71
65
|
activate() {
|
72
66
|
if (this._isActive) {
|
73
67
|
return;
|
74
68
|
}
|
75
|
-
|
76
69
|
if (this._config.autofocus) {
|
77
70
|
this._config.trapElement.focus();
|
78
71
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
EventHandler__default.default.on(document, EVENT_FOCUSIN, event => this._handleFocusin(event));
|
83
|
-
EventHandler__default.default.on(document, EVENT_KEYDOWN_TAB, event => this._handleKeydown(event));
|
72
|
+
EventHandler.off(document, EVENT_KEY); // guard against infinite focus loop
|
73
|
+
EventHandler.on(document, EVENT_FOCUSIN, event => this._handleFocusin(event));
|
74
|
+
EventHandler.on(document, EVENT_KEYDOWN_TAB, event => this._handleKeydown(event));
|
84
75
|
this._isActive = true;
|
85
76
|
}
|
86
|
-
|
87
77
|
deactivate() {
|
88
78
|
if (!this._isActive) {
|
89
79
|
return;
|
90
80
|
}
|
91
|
-
|
92
81
|
this._isActive = false;
|
93
|
-
|
94
|
-
}
|
95
|
-
|
82
|
+
EventHandler.off(document, EVENT_KEY);
|
83
|
+
}
|
96
84
|
|
85
|
+
// Private
|
97
86
|
_handleFocusin(event) {
|
98
87
|
const {
|
99
88
|
trapElement
|
100
89
|
} = this._config;
|
101
|
-
|
102
90
|
if (event.target === document || event.target === trapElement || trapElement.contains(event.target)) {
|
103
91
|
return;
|
104
92
|
}
|
105
|
-
|
106
|
-
const elements = SelectorEngine__default.default.focusableChildren(trapElement);
|
107
|
-
|
93
|
+
const elements = SelectorEngine.focusableChildren(trapElement);
|
108
94
|
if (elements.length === 0) {
|
109
95
|
trapElement.focus();
|
110
96
|
} else if (this._lastTabNavDirection === TAB_NAV_BACKWARD) {
|
@@ -113,15 +99,12 @@
|
|
113
99
|
elements[0].focus();
|
114
100
|
}
|
115
101
|
}
|
116
|
-
|
117
102
|
_handleKeydown(event) {
|
118
103
|
if (event.key !== TAB_KEY) {
|
119
104
|
return;
|
120
105
|
}
|
121
|
-
|
122
106
|
this._lastTabNavDirection = event.shiftKey ? TAB_NAV_BACKWARD : TAB_NAV_FORWARD;
|
123
107
|
}
|
124
|
-
|
125
108
|
}
|
126
109
|
|
127
110
|
return FocusTrap;
|