@instructure/ui-a11y-utils 11.6.0 → 11.6.1-pr-snapshot-1779894247159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [11.6.1-pr-snapshot-1779894247159](https://github.com/instructure/instructure-ui/compare/v11.6.0...v11.6.1-pr-snapshot-1779894247159) (2026-05-27)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-a11y-utils
9
+
10
+
11
+
12
+
13
+
6
14
  # [11.6.0](https://github.com/instructure/instructure-ui/compare/v11.5.0...v11.6.0) (2026-02-18)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/ui-a11y-utils
@@ -1,13 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.hasVisibleChildren = hasVisibleChildren;
8
- var _react = require("react");
9
- var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
10
- var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
11
1
  /*
12
2
  * The MIT License (MIT)
13
3
  *
@@ -32,22 +22,16 @@ var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReade
32
22
  * SOFTWARE.
33
23
  */
34
24
 
35
- /**
36
- * ---
37
- * category: utilities/a11y
38
- * ---
39
- * Returns `true` if any of the children are not wrapped with [ScreenReaderContent](ScreenReaderContent).
40
- * @module hasVisibleChildren
41
- * @param children - A React component's children prop
42
- * @return whether any of the children are visible
43
- */
44
- function hasVisibleChildren(children) {
45
- let visible = false;
46
- _react.Children.forEach(children, child => {
47
- if (child && !(0, _matchComponentTypes.matchComponentTypes)(child, [_ScreenReaderContent.ScreenReaderContent])) {
48
- visible = true;
49
- }
50
- });
51
- return visible;
25
+ module.exports = {
26
+ presets: [
27
+ [
28
+ require('@instructure/ui-babel-preset'),
29
+ {
30
+ coverage: Boolean(process.env.COVERAGE),
31
+ esModules: Boolean(process.env.ES_MODULES),
32
+ removeConsole: process.env.NODE_ENV === 'production',
33
+ transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
34
+ }
35
+ ]
36
+ ]
52
37
  }
53
- var _default = exports.default = hasVisibleChildren;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@instructure/ui-a11y-utils",
3
- "version": "11.6.0",
3
+ "version": "11.6.1-pr-snapshot-1779894247159",
4
+ "type": "module",
4
5
  "description": "A collection of utilities for managing focus and screen reader behavior",
5
6
  "author": "Instructure, Inc. Engineering and Product Design",
6
7
  "module": "./es/index.js",
7
- "main": "./lib/index.js",
8
8
  "types": "./types/index.d.ts",
9
9
  "repository": {
10
10
  "type": "git",
@@ -16,19 +16,19 @@
16
16
  "dependencies": {
17
17
  "@babel/runtime": "^7.27.6",
18
18
  "keycode": "^2",
19
- "@instructure/console": "11.6.0",
20
- "@instructure/shared-types": "11.6.0",
21
- "@instructure/ui-a11y-content": "11.6.0",
22
- "@instructure/ui-dom-utils": "11.6.0",
23
- "@instructure/ui-react-utils": "11.6.0",
24
- "@instructure/uid": "11.6.0"
19
+ "@instructure/console": "11.6.1-pr-snapshot-1779894247159",
20
+ "@instructure/shared-types": "11.6.1-pr-snapshot-1779894247159",
21
+ "@instructure/ui-a11y-content": "11.6.1-pr-snapshot-1779894247159",
22
+ "@instructure/ui-dom-utils": "11.6.1-pr-snapshot-1779894247159",
23
+ "@instructure/ui-react-utils": "11.6.1-pr-snapshot-1779894247159",
24
+ "@instructure/uid": "11.6.1-pr-snapshot-1779894247159"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@testing-library/jest-dom": "^6.6.3",
28
28
  "@testing-library/react": "15.0.7",
29
29
  "vitest": "^3.2.2",
30
- "@instructure/ui-babel-preset": "11.6.0",
31
- "@instructure/ui-color-utils": "11.6.0"
30
+ "@instructure/ui-babel-preset": "11.6.1-pr-snapshot-1779894247159",
31
+ "@instructure/ui-color-utils": "11.6.1-pr-snapshot-1779894247159"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": ">=18 <=19"
@@ -41,10 +41,8 @@
41
41
  ".": {
42
42
  "types": "./types/index.d.ts",
43
43
  "import": "./es/index.js",
44
- "require": "./lib/index.js",
45
44
  "default": "./es/index.js"
46
45
  },
47
- "./lib/*": "./lib/*",
48
46
  "./es/*": "./es/*",
49
47
  "./types/*": "./types/*",
50
48
  "./package.json": "./package.json",
@@ -54,7 +52,7 @@
54
52
  "lint": "ui-scripts lint",
55
53
  "lint:fix": "ui-scripts lint --fix",
56
54
  "clean": "ui-scripts clean",
57
- "build": "ui-scripts build --modules es,cjs",
55
+ "build": "ui-scripts build",
58
56
  "build:watch": "ui-scripts build --watch",
59
57
  "build:types": "tsc -p tsconfig.build.json"
60
58
  }
@@ -1,236 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.FocusRegion = void 0;
8
- var _keycode = _interopRequireDefault(require("keycode"));
9
- var _contains = require("@instructure/ui-dom-utils/lib/contains.js");
10
- var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
11
- var _ownerDocument2 = require("@instructure/ui-dom-utils/lib/ownerDocument.js");
12
- var _findTabbable = require("@instructure/ui-dom-utils/lib/findTabbable.js");
13
- var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
14
- var _uid = require("@instructure/uid");
15
- var _console = require("@instructure/console");
16
- var _ScreenReaderFocusRegion = require("./ScreenReaderFocusRegion");
17
- var _KeyboardFocusRegion = require("./KeyboardFocusRegion");
18
- /*
19
- * The MIT License (MIT)
20
- *
21
- * Copyright (c) 2015 - present Instructure, Inc.
22
- *
23
- * Permission is hereby granted, free of charge, to any person obtaining a copy
24
- * of this software and associated documentation files (the "Software"), to deal
25
- * in the Software without restriction, including without limitation the rights
26
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
- * copies of the Software, and to permit persons to whom the Software is
28
- * furnished to do so, subject to the following conditions:
29
- *
30
- * The above copyright notice and this permission notice shall be included in all
31
- * copies or substantial portions of the Software.
32
- *
33
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
- * SOFTWARE.
40
- */
41
-
42
- /**
43
- * ---
44
- * category: utilities/a11y
45
- * ---
46
- *
47
- * Class for focus operations, manages [ScreenReaderFocusRegion](ScreenReaderFocusRegion)
48
- * and [KeyboardFocusRegion](KeyboardFocusRegion) for the given DOM element.
49
- * - Scoping focus within a given context (DOM node),
50
- * - Mark active element for focus later
51
- * - Return focus to the marked element
52
- * @module FocusRegion
53
- */
54
- class FocusRegion {
55
- constructor(element, options) {
56
- this._contextElement = null;
57
- this._options = void 0;
58
- this._screenReaderFocusRegion = void 0;
59
- this._keyboardFocusRegion = void 0;
60
- this._id = void 0;
61
- this._mouseDownListener = void 0;
62
- this._clickListener = void 0;
63
- this._mouseUpListener = void 0;
64
- this._keyUpListener = void 0;
65
- this._active = false;
66
- this._documentClickTarget = null;
67
- this._contextContainsTarget = false;
68
- this.handleDismiss = (event, documentClick) => {
69
- var _this$_options$onDism, _this$_options;
70
- (_this$_options$onDism = (_this$_options = this._options).onDismiss) === null || _this$_options$onDism === void 0 ? void 0 : _this$_options$onDism.call(_this$_options, event, documentClick);
71
- };
72
- this.captureDocumentMousedown = event => {
73
- this._documentClickTarget = event.target;
74
- this._contextContainsTarget = (0, _contains.contains)(this._contextElement, this._documentClickTarget);
75
- };
76
- this.handleDocumentClick = event => {
77
- // we used event.pointerType === 'mouse' here, but it is not supported in Safari
78
- // https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType
79
- // TODO: Check this in the future, because the linked Webkit bug is marked as fixed in 2025-09
80
- if (this._options.shouldCloseOnDocumentClick && event.button === 0 && event.detail > 0 &&
81
- // if event.detail is 0 then this is a keyboard and not a mouse press
82
- !this._contextContainsTarget &&
83
- //this prevents clicking on Tooltip from closing the parent dialog
84
- !(_canUseDOM.canUseDOM && this._documentClickTarget instanceof HTMLElement && this._documentClickTarget.closest('[role="tooltip"]'))) {
85
- this.handleDismiss(event, true);
86
- }
87
- };
88
- this.handleFrameClick = (event, frame) => {
89
- if (!(0, _contains.contains)(this._contextElement, frame)) {
90
- // dismiss if frame is not within the region
91
- this.handleDismiss(event, true);
92
- }
93
- };
94
- this.handleKeyUp = event => {
95
- if (this._options.shouldCloseOnEscape && event.keyCode === _keycode.default.codes.esc && !event.defaultPrevented) {
96
- var _ownerDocument;
97
- // If a dialog contains an <input type="file"/> element and the user opens the file picker and closes it with the
98
- // escape key then Firefox passes through that event which could close the parent dialog. This code prevents that
99
- // from happening (listening for a `cancel` event doesn't seem to work in firefox)
100
- const activeElement = (_ownerDocument = (0, _ownerDocument2.ownerDocument)(this._contextElement)) === null || _ownerDocument === void 0 ? void 0 : _ownerDocument.activeElement;
101
- const fileInputFocused = (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'INPUT' && activeElement.type === 'file';
102
- if (fileInputFocused) {
103
- ;
104
- activeElement.blur();
105
- } else {
106
- //This should prevent a Tooltip from closing when inside of a Modal
107
- if (this._options.isTooltip) {
108
- event.stopPropagation();
109
- }
110
- this.handleDismiss(event);
111
- }
112
- }
113
- };
114
- this._options = options || {
115
- shouldCloseOnDocumentClick: true,
116
- shouldCloseOnEscape: true,
117
- isTooltip: false
118
- };
119
- this._id = (0, _uid.uid)();
120
- // eslint-disable-next-line no-param-reassign
121
- options.regionId = this._id;
122
- this._contextElement = element;
123
- this._screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(element, options);
124
- this._keyboardFocusRegion = new _KeyboardFocusRegion.KeyboardFocusRegion(element, options);
125
- }
126
- updateElement(element, options) {
127
- this._contextElement = element;
128
- if (options) {
129
- this._options = options;
130
- if (this._active) {
131
- this.addOrRemoveListeners(options.shouldCloseOnDocumentClick, options.shouldCloseOnEscape);
132
- }
133
- }
134
- if (this._keyboardFocusRegion) {
135
- this._keyboardFocusRegion.updateElement(element);
136
- }
137
- if (this._screenReaderFocusRegion) {
138
- this._screenReaderFocusRegion.updateElement(element);
139
- }
140
- }
141
- get id() {
142
- return this._id;
143
- }
144
-
145
- // Focused returns when the focus region is active. Checking focused with the active element
146
- // is inconsistent across browsers (Safari/Firefox do not focus elements on click)
147
- get focused() {
148
- return this._active;
149
- }
150
- get keyboardFocusable() {
151
- return ((0, _findTabbable.findTabbable)(this._contextElement) || []).length > 0;
152
- }
153
-
154
- /**
155
- * Adds or removes mouse/keyboard listeners based on the input parameters
156
- * @param shouldCloseOnDocumentClick Should add listeners that close the region if there is an outside click?
157
- * @param shouldCloseOnEscape Should the region be closed if ESC is pressed?
158
- */
159
- addOrRemoveListeners(shouldCloseOnDocumentClick, shouldCloseOnEscape) {
160
- const doc = (0, _ownerDocument2.ownerDocument)(this._contextElement);
161
- if (shouldCloseOnDocumentClick) {
162
- if (!this._mouseDownListener) {
163
- this._mouseDownListener = (0, _addEventListener.addEventListener)(doc, 'mousedown', this.captureDocumentMousedown);
164
- }
165
- if (!this._clickListener) {
166
- this._clickListener = (0, _addEventListener.addEventListener)(doc, 'click', this.handleDocumentClick);
167
- }
168
- Array.from(doc.getElementsByTagName('iframe')).forEach(el => {
169
- // listen for mouseup events on any iframes in the document
170
- const frameDoc = el.contentDocument;
171
- if (frameDoc && !this._mouseUpListener) {
172
- this._mouseUpListener = (0, _addEventListener.addEventListener)(frameDoc, 'mouseup', event => {
173
- this.handleFrameClick(event, el);
174
- });
175
- }
176
- });
177
- } else {
178
- var _this$_mouseDownListe, _this$_clickListener, _this$_mouseUpListene;
179
- (_this$_mouseDownListe = this._mouseDownListener) === null || _this$_mouseDownListe === void 0 ? void 0 : _this$_mouseDownListe.remove();
180
- this._mouseDownListener = void 0;
181
- (_this$_clickListener = this._clickListener) === null || _this$_clickListener === void 0 ? void 0 : _this$_clickListener.remove();
182
- this._clickListener = void 0;
183
- (_this$_mouseUpListene = this._mouseUpListener) === null || _this$_mouseUpListene === void 0 ? void 0 : _this$_mouseUpListene.remove();
184
- this._mouseUpListener = void 0;
185
- }
186
- if (shouldCloseOnEscape) {
187
- if (!this._keyUpListener) {
188
- //This will ensure that the Tooltip's Escape event listener is executed first
189
- //because listeners in the capturing phase are called before other event listeners (like that of the Modal's Escape listener)
190
- //so a Modal with a Tooltip will not get closed when closing the Tooltip with Escape
191
- const useCapture = this._options.isTooltip;
192
- this._keyUpListener = (0, _addEventListener.addEventListener)(doc, 'keyup', this.handleKeyUp, useCapture);
193
- }
194
- } else {
195
- var _this$_keyUpListener;
196
- (_this$_keyUpListener = this._keyUpListener) === null || _this$_keyUpListener === void 0 ? void 0 : _this$_keyUpListener.remove();
197
- this._keyUpListener = void 0;
198
- }
199
- }
200
- activate() {
201
- if (!this._active) {
202
- this._keyboardFocusRegion.activate();
203
- this._screenReaderFocusRegion.activate();
204
- this.addOrRemoveListeners(this._options.shouldCloseOnDocumentClick, this._options.shouldCloseOnEscape);
205
- this._active = true;
206
- }
207
- }
208
- deactivate({
209
- keyboard = true
210
- } = {}) {
211
- var _this$_mouseDownListe2, _this$_clickListener2, _this$_mouseUpListene2, _this$_keyUpListener2;
212
- (_this$_mouseDownListe2 = this._mouseDownListener) === null || _this$_mouseDownListe2 === void 0 ? void 0 : _this$_mouseDownListe2.remove();
213
- this._mouseDownListener = void 0;
214
- (_this$_clickListener2 = this._clickListener) === null || _this$_clickListener2 === void 0 ? void 0 : _this$_clickListener2.remove();
215
- this._clickListener = void 0;
216
- (_this$_mouseUpListene2 = this._mouseUpListener) === null || _this$_mouseUpListene2 === void 0 ? void 0 : _this$_mouseUpListene2.remove();
217
- this._mouseUpListener = void 0;
218
- (_this$_keyUpListener2 = this._keyUpListener) === null || _this$_keyUpListener2 === void 0 ? void 0 : _this$_keyUpListener2.remove();
219
- this._keyUpListener = void 0;
220
- if (keyboard) {
221
- this._keyboardFocusRegion.deactivate();
222
- }
223
- this._screenReaderFocusRegion.deactivate();
224
- this._active = false;
225
- }
226
- focus() {
227
- (0, _console.logError)(this._active, `[FocusRegion] Cannot call '.focus()' on a region that is not currently active.`);
228
- this._keyboardFocusRegion.focus();
229
- }
230
- blur() {
231
- (0, _console.logError)(!this._active, `[FocusRegion] Cannot call '.blur()' on a region that is currently active.`);
232
- this._keyboardFocusRegion.blur();
233
- }
234
- }
235
- exports.FocusRegion = FocusRegion;
236
- var _default = exports.default = FocusRegion;
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.FocusRegionManager = void 0;
7
- var _console = require("@instructure/console");
8
- var _FocusRegion = require("./FocusRegion");
9
- var _FocusRegionManager;
10
- /*
11
- * The MIT License (MIT)
12
- *
13
- * Copyright (c) 2015 - present Instructure, Inc.
14
- *
15
- * Permission is hereby granted, free of charge, to any person obtaining a copy
16
- * of this software and associated documentation files (the "Software"), to deal
17
- * in the Software without restriction, including without limitation the rights
18
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
- * copies of the Software, and to permit persons to whom the Software is
20
- * furnished to do so, subject to the following conditions:
21
- *
22
- * The above copyright notice and this permission notice shall be included in all
23
- * copies or substantial portions of the Software.
24
- *
25
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
32
- */
33
- let ENTRIES = [];
34
-
35
- /**
36
- * ---
37
- * category: utilities/a11y
38
- * ---
39
- *
40
- * Class for focus operations, manages multiple [FocusRegion](FocusRegion)s.
41
- * - Scoping focus within a given context,
42
- * - Mark active element for focus later
43
- * - Return focus to the marked element
44
- * @module FocusManager
45
- */
46
- class FocusRegionManager {}
47
- exports.FocusRegionManager = FocusRegionManager;
48
- _FocusRegionManager = FocusRegionManager;
49
- FocusRegionManager.focusRegion = (element, idOrOptions = {}) => {
50
- let entry;
51
- if (typeof idOrOptions === 'string') {
52
- entry = _FocusRegionManager.getEntry(element, idOrOptions);
53
- } else {
54
- entry = _FocusRegionManager.addEntry(element, idOrOptions);
55
- }
56
- if (entry && entry.region && typeof entry.region.focus === 'function') {
57
- entry.region.focus();
58
- return entry.region;
59
- } else {
60
- (0, _console.logError)(false, `[FocusRegionManager] Could not focus region with element: ${element}`);
61
- }
62
- return;
63
- };
64
- FocusRegionManager.activateRegion = (element, options) => {
65
- const _FocusRegionManager$a = _FocusRegionManager.addEntry(element, options),
66
- region = _FocusRegionManager$a.region;
67
- return region;
68
- };
69
- FocusRegionManager.getActiveEntry = () => {
70
- return ENTRIES.find(({
71
- region
72
- }) => region.focused);
73
- };
74
- FocusRegionManager.findEntry = (element, id) => {
75
- let index;
76
- if (id) {
77
- index = ENTRIES.findIndex(entry => entry.id === id);
78
- } else {
79
- index = ENTRIES.findIndex(entry => entry.element === element);
80
- }
81
- return index;
82
- };
83
- FocusRegionManager.getEntry = (element, id) => {
84
- return ENTRIES[_FocusRegionManager.findEntry(element, id)];
85
- };
86
- FocusRegionManager.addEntry = (element, options = {}) => {
87
- const region = new _FocusRegion.FocusRegion(element, options);
88
- const activeEntry = _FocusRegionManager.getActiveEntry();
89
- const keyboardFocusable = region.keyboardFocusable;
90
- ENTRIES.forEach(({
91
- region
92
- }) => {
93
- if (region) {
94
- // If the active region is triggering a new focus region that does not have
95
- // keyboard focusable content, don't deactivate the active region's keyboard
96
- // focus region
97
- const keyboard = region.focused && !keyboardFocusable ? {
98
- keyboard: false
99
- } : void 0;
100
- region.deactivate(keyboard);
101
- }
102
- });
103
- region.activate();
104
- if (options.shouldFocusOnOpen) {
105
- region.focus();
106
- }
107
- const entry = {
108
- id: region.id,
109
- element,
110
- region,
111
- children: [],
112
- parent: activeEntry
113
- };
114
- ENTRIES.push(entry);
115
- if (activeEntry) {
116
- activeEntry.children.push(entry);
117
- }
118
- return entry;
119
- };
120
- FocusRegionManager.removeEntry = (element, id) => {
121
- const index = _FocusRegionManager.findEntry(element, id);
122
- const entry = ENTRIES[index];
123
- if (index > -1) {
124
- ENTRIES.splice(index, 1);
125
- }
126
- return entry;
127
- };
128
- FocusRegionManager.isFocused = (element, id) => {
129
- const entry = _FocusRegionManager.getActiveEntry();
130
- if (id) {
131
- return entry && entry.region && entry.id === id;
132
- } else {
133
- return entry && entry.region && entry.element === element;
134
- }
135
- };
136
- FocusRegionManager.clearEntries = () => {
137
- ENTRIES = [];
138
- };
139
- FocusRegionManager.blurRegion = (element, id) => {
140
- const entry = _FocusRegionManager.removeEntry(element, id);
141
- if (entry) {
142
- const children = entry.children,
143
- region = entry.region,
144
- parent = entry.parent;
145
-
146
- // deactivate the region...
147
- region && region.deactivate();
148
-
149
- // and any regions created from it
150
- if (children) {
151
- children.forEach(({
152
- id,
153
- element
154
- }) => {
155
- const entry = _FocusRegionManager.removeEntry(element, id);
156
- entry && entry.region && entry.region.deactivate();
157
- });
158
- }
159
-
160
- // activate the region's parent if it exists
161
- parent && parent.region && parent.region.activate();
162
- region && region.blur(); // this should focus the parent region
163
- }
164
- };
165
- var _default = exports.default = FocusRegionManager;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.KeyboardFocusRegion = void 0;
8
- var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
9
- var _findTabbable = require("@instructure/ui-dom-utils/lib/findTabbable.js");
10
- var _findFocusable = require("@instructure/ui-dom-utils/lib/findFocusable.js");
11
- var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
12
- var _getActiveElement = require("@instructure/ui-dom-utils/lib/getActiveElement.js");
13
- var _addEventListener = require("@instructure/ui-dom-utils/lib/addEventListener.js");
14
- var _ownerDocument = require("@instructure/ui-dom-utils/lib/ownerDocument.js");
15
- var _containsActiveElement = require("@instructure/ui-dom-utils/lib/containsActiveElement.js");
16
- var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
17
- var _console = require("@instructure/console");
18
- var _keycode = _interopRequireDefault(require("keycode"));
19
- var _scopeTab = require("./scopeTab");
20
- /*
21
- * The MIT License (MIT)
22
- *
23
- * Copyright (c) 2015 - present Instructure, Inc.
24
- *
25
- * Permission is hereby granted, free of charge, to any person obtaining a copy
26
- * of this software and associated documentation files (the "Software"), to deal
27
- * in the Software without restriction, including without limitation the rights
28
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
- * copies of the Software, and to permit persons to whom the Software is
30
- * furnished to do so, subject to the following conditions:
31
- *
32
- * The above copyright notice and this permission notice shall be included in all
33
- * copies or substantial portions of the Software.
34
- *
35
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
- * SOFTWARE.
42
- */
43
-
44
- /**
45
- * ---
46
- * category: utilities/a11y
47
- * ---
48
- *
49
- * Class for focus operations.
50
- * - Scoping focus within a given context (DOM node),
51
- * - Mark active element for focus later
52
- * - Return focus to the marked element
53
- * @module KeyboardFocusRegion
54
- */
55
- class KeyboardFocusRegion {
56
- constructor(element, options) {
57
- this._options = void 0;
58
- this._focusLaterElement = null;
59
- this._needToFocus = false;
60
- this._listeners = [];
61
- this._raf = [];
62
- this._active = false;
63
- this._wasDocumentClick = void 0;
64
- this._contextElement = void 0;
65
- this.handleKeyDown = event => {
66
- if (event.keyCode === _keycode.default.codes.tab) {
67
- (0, _scopeTab.scopeTab)(this._contextElement, event);
68
- }
69
- };
70
- this.handleClick = () => {
71
- this._wasDocumentClick = true;
72
- };
73
- this.handleWindowBlur = () => {
74
- if (this._wasDocumentClick) {
75
- this._wasDocumentClick = false;
76
- return;
77
- }
78
- this._needToFocus = true;
79
- };
80
- this.handleFocus = () => {
81
- if (this._needToFocus) {
82
- this._needToFocus = false;
83
- if (!this._contextElement) {
84
- return;
85
- }
86
- // need to see how jQuery shims document.on('focusin') so we don't need the
87
- // setTimeout, firefox doesn't support focusin, if it did, we could focus
88
- // the element outside of a setTimeout. Side-effect of this implementation
89
- // is that the document.body gets focus, and then we focus our element right
90
- // after, seems fine.
91
- this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(() => {
92
- if ((0, _containsActiveElement.containsActiveElement)(this._contextElement)) {
93
- return;
94
- }
95
- this.focusDefaultElement();
96
- }));
97
- }
98
- };
99
- this.handleFirstTabbableKeyDown = event => {
100
- if (event.keyCode === _keycode.default.codes.tab && event.shiftKey) {
101
- var _this$_options$onBlur, _this$_options;
102
- (_this$_options$onBlur = (_this$_options = this._options).onBlur) === null || _this$_options$onBlur === void 0 ? void 0 : _this$_options$onBlur.call(_this$_options, event);
103
- }
104
- };
105
- this.handleLastTabbableKeyDown = event => {
106
- if (event.keyCode === _keycode.default.codes.tab && !event.shiftKey) {
107
- var _this$_options$onBlur2, _this$_options2;
108
- (_this$_options$onBlur2 = (_this$_options2 = this._options).onBlur) === null || _this$_options$onBlur2 === void 0 ? void 0 : _this$_options$onBlur2.call(_this$_options2, event);
109
- }
110
- };
111
- this._contextElement = (0, _findDOMNode.findDOMNode)(element);
112
- this._options = options || {
113
- shouldContainFocus: true,
114
- shouldReturnFocus: true,
115
- defaultFocusElement: null
116
- };
117
- if (this._options.shouldReturnFocus) {
118
- this._focusLaterElement = (0, _getActiveElement.getActiveElement)(this.doc);
119
- }
120
- }
121
- get focused() {
122
- return (0, _containsActiveElement.containsActiveElement)(this._contextElement);
123
- }
124
- get shouldContainFocus() {
125
- const shouldContainFocus = this._options.shouldContainFocus;
126
- return shouldContainFocus === true || Array.isArray(shouldContainFocus) && shouldContainFocus.includes('keyboard');
127
- }
128
- get focusable() {
129
- return (0, _findFocusable.findFocusable)(this._contextElement, () => true, true) || [];
130
- }
131
- get tabbable() {
132
- return (0, _findTabbable.findTabbable)(this._contextElement) || [];
133
- }
134
- get firstTabbable() {
135
- return this.tabbable[0];
136
- }
137
- get lastTabbable() {
138
- return this.tabbable.pop();
139
- }
140
- get firstFocusable() {
141
- return this.focusable[0];
142
- }
143
- get lastFocusable() {
144
- return this.focusable.pop();
145
- }
146
- get doc() {
147
- return (0, _ownerDocument.ownerDocument)(this._contextElement);
148
- }
149
- get win() {
150
- return (0, _ownerWindow.ownerWindow)(this._contextElement);
151
- }
152
- get defaultFocusElement() {
153
- const defaultFocusElement = this._options.defaultFocusElement;
154
- const element = (0, _findDOMNode.findDOMNode)(typeof defaultFocusElement === 'function' ? defaultFocusElement() : defaultFocusElement);
155
- if (element && this._contextElement && this._contextElement.contains(element)) {
156
- return element;
157
- }
158
- if (this.firstTabbable) {
159
- return this.firstTabbable;
160
- }
161
- if (this._contextElement && this.focusable.includes(this._contextElement)) {
162
- return this._contextElement;
163
- }
164
- return null;
165
- }
166
- updateElement(element) {
167
- this._contextElement = (0, _findDOMNode.findDOMNode)(element);
168
- }
169
- focusDefaultElement() {
170
- if (this.defaultFocusElement) {
171
- const focusElement = this.defaultFocusElement;
172
- const positionContainer = focusElement.closest('[data-position-content]');
173
- if (!positionContainer) {
174
- focusElement.focus();
175
- } else {
176
- this.tryFocusOnPositionedElement(positionContainer, focusElement);
177
- }
178
- } else {
179
- if (this.shouldContainFocus) {
180
- // Blur the active element to place focus on the document body
181
- (0, _getActiveElement.getActiveElement)(this.doc) && (0, _getActiveElement.getActiveElement)(this.doc).blur();
182
- (0, _console.logError)(true, `
183
- [KeyboardFocusRegion] No \`defaultFocusElement\` was provided and
184
- \`shouldContainFocus\` was set to \`true\` or \`keyboard\`. Focus has
185
- been moved to the document body instead.`);
186
- }
187
- }
188
- }
189
- tryFocusOnPositionedElement(positionContainer, focusElement, tries = 3) {
190
- // If element is positioned by `ui-position`
191
- // we may need to wait for it to appear in
192
- // correct place before triggering focus.
193
- // Otherwise it will cause a scroll to the top of the page.
194
-
195
- if (tries <= 0) {
196
- return;
197
- }
198
- const positionRect = positionContainer.getBoundingClientRect();
199
- const docRect = document.documentElement.getBoundingClientRect();
200
-
201
- // Check if element is outside of visible part of page (including parts hidden by scroll).
202
- const isHiddenOutside = positionRect.top > docRect.bottom || positionRect.right < docRect.left || positionRect.bottom < docRect.top || positionRect.left > docRect.right;
203
- if (!isHiddenOutside) {
204
- focusElement.focus();
205
- } else {
206
- this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(() => {
207
- this.tryFocusOnPositionedElement(positionContainer, focusElement, tries - 1);
208
- }));
209
- }
210
- }
211
- focus() {
212
- if (this.focused) {
213
- return;
214
- }
215
- this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(() => {
216
- this.focusDefaultElement();
217
- }));
218
- }
219
- blur() {
220
- if (this._options.shouldReturnFocus && this._focusLaterElement) {
221
- try {
222
- ;
223
- this._focusLaterElement.focus();
224
- } catch (e) {
225
- (0, _console.logError)(false, `
226
- [KeyboardFocusRegion] You tried to return focus to ${this._focusLaterElement}
227
- but it is not in the DOM anymore: ${e}
228
- `);
229
- }
230
- this._focusLaterElement = null;
231
- }
232
- }
233
- activate() {
234
- const defaultFocusElement = this.defaultFocusElement,
235
- shouldContainFocus = this.shouldContainFocus;
236
- if (!this._active) {
237
- if (defaultFocusElement || shouldContainFocus) {
238
- if (shouldContainFocus) {
239
- this._listeners.push((0, _addEventListener.addEventListener)(this.doc, 'keydown', this.handleKeyDown));
240
- } else {
241
- this._listeners.push((0, _addEventListener.addEventListener)(this.firstTabbable || defaultFocusElement, 'keydown', this.handleFirstTabbableKeyDown));
242
- this._listeners.push((0, _addEventListener.addEventListener)(this.lastTabbable || defaultFocusElement, 'keydown', this.handleLastTabbableKeyDown));
243
- }
244
- this._listeners.push((0, _addEventListener.addEventListener)(this.doc, 'click', this.handleClick, true));
245
- this._listeners.push((0, _addEventListener.addEventListener)(this.win, 'blur', this.handleWindowBlur, false));
246
- this._listeners.push((0, _addEventListener.addEventListener)(this.doc, 'focus', this.handleFocus, true));
247
- this._active = true;
248
- }
249
- }
250
- }
251
- deactivate() {
252
- if (this._active) {
253
- this._listeners.forEach(listener => {
254
- listener.remove();
255
- });
256
- this._listeners = [];
257
- this._raf.forEach(request => request.cancel());
258
- this._raf = [];
259
- this._active = false;
260
- }
261
- }
262
- }
263
- exports.KeyboardFocusRegion = KeyboardFocusRegion;
264
- var _default = exports.default = KeyboardFocusRegion;
@@ -1,188 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.ScreenReaderFocusRegion = void 0;
7
- var _console = require("@instructure/console");
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- function isElement(elem) {
33
- return elem instanceof Element;
34
- }
35
-
36
- /**
37
- * ---
38
- * category: utilities/a11y
39
- * ---
40
- *
41
- * Utility that hides all DOM elements outside of a specified node. Used,
42
- * for example, in overlay components where we want to restrict the screen
43
- * readers to the overlay content.
44
- * @module ScreenReaderFocusRegion
45
- */
46
- class ScreenReaderFocusRegion {
47
- constructor(element, options = {
48
- shouldContainFocus: true,
49
- liveRegion: []
50
- }) {
51
- this._parents = [];
52
- this._nodes = [];
53
- this._liveRegion = void 0;
54
- this._contextElement = void 0;
55
- this._options = void 0;
56
- this._observer = null;
57
- this._attributes = [];
58
- this.handleDOMMutation = records => {
59
- records.forEach(record => {
60
- const addedNodes = Array.from(record.addedNodes);
61
- const removedNodes = Array.from(record.removedNodes);
62
- this.hideNodes(addedNodes.filter(isElement));
63
- removedNodes.filter(isElement).forEach(removedNode => {
64
- // Node has been removed from the DOM, make sure it is
65
- // removed from our list of hidden nodes as well
66
-
67
- if (removedNode.tagName.toLowerCase() !== 'iframe') {
68
- this.restoreNode(removedNode);
69
- }
70
- const iframeBodies = this.parseIframeBodies(removedNode);
71
- iframeBodies.forEach(iframeBody => {
72
- this.restoreNode(iframeBody);
73
- });
74
- });
75
- });
76
- };
77
- const liveRegion = typeof options.liveRegion === 'function' ? options.liveRegion() : options.liveRegion;
78
- this._liveRegion = Array.isArray(liveRegion) ? liveRegion : [liveRegion];
79
- this._contextElement = element;
80
- this._options = options;
81
- }
82
- updateElement(element) {
83
- this._contextElement = element;
84
- }
85
- muteNode(node) {
86
- if (node && node.tagName.toLowerCase() !== 'script') {
87
- // When we are trapping screen reader focus on an element that
88
- // is deep inside the DOM, we can't apply aria-hidden to the
89
- // parents, so parent regions will be read if they have a role
90
- // and/or aria-label assigned. To optimize SR ux we remove the role,
91
- // aria-label, and aria-hidden attrs temporarily when the region
92
- // is focused, and then we restore them when focus is lost.
93
- ;
94
- ['role', 'aria-label', 'aria-hidden' // this should never happen right?
95
- ].forEach(attribute => {
96
- const value = node.getAttribute(attribute);
97
- if (value !== null) {
98
- this._attributes.push([node, attribute, value]);
99
- node.removeAttribute(attribute);
100
- }
101
- });
102
- this._observer.observe(node, {
103
- childList: true
104
- });
105
- }
106
- }
107
- hideNodes(nodes) {
108
- nodes.forEach(node => {
109
- var _node$getAttribute;
110
- const ariaLive = typeof node.getAttribute === 'function' && ((_node$getAttribute = node.getAttribute('aria-live')) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.toLowerCase());
111
- if (node && node.nodeType === 1 && node.tagName.toLowerCase() !== 'script' && ariaLive !== 'assertive' && ariaLive !== 'polite' && this._parents.indexOf(node) === -1 && this._nodes.indexOf(node) === -1 && this._liveRegion.indexOf(node) === -1 && !this._contextElement.contains(node)) {
112
- if (node.tagName.toLowerCase() !== 'iframe') {
113
- this.hideNode(node);
114
- }
115
- const iframeBodies = this.parseIframeBodies(node);
116
- iframeBodies.forEach(iframeBody => {
117
- this.hideNode(iframeBody);
118
- });
119
- }
120
- });
121
- }
122
- hideNode(node) {
123
- if (node.getAttribute('aria-hidden') !== 'true') {
124
- node.setAttribute('aria-hidden', 'true');
125
- this._nodes.push(node);
126
- }
127
- }
128
- restoreNode(removedNode) {
129
- const index = this._nodes.indexOf(removedNode);
130
- if (index >= 0) {
131
- removedNode.removeAttribute('aria-hidden');
132
- this._nodes.splice(index, 1);
133
- }
134
- }
135
- parseIframeBodies(node) {
136
- if (!node) return [];
137
- let iframes = [];
138
- if (node.tagName.toLowerCase() === 'iframe') {
139
- iframes.push(node);
140
- } else {
141
- if (node.getElementsByTagName) {
142
- iframes = Array.from(node.getElementsByTagName('iframe'));
143
- }
144
- }
145
- return iframes.map(iframe => {
146
- let body = null;
147
- try {
148
- body = iframe.contentDocument.body;
149
- } catch (e) {
150
- (0, _console.logWarn)(false, `[ui-a11y] could not find a document for iframe: ${e} ${iframe}`);
151
- }
152
- return body;
153
- }).filter(body => body !== null);
154
- }
155
- activate() {
156
- if (!this._options.shouldContainFocus) {
157
- return;
158
- }
159
- this._observer = new MutationObserver(this.handleDOMMutation);
160
- let node = this._contextElement;
161
- while (node && node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() !== 'body') {
162
- const parent = node.parentElement;
163
- if (parent) {
164
- this._parents.push(parent);
165
- this.muteNode(parent);
166
- this.hideNodes(Array.prototype.slice.call(parent.childNodes));
167
- }
168
- node = node.parentNode; // should never be null, will default to doc element
169
- }
170
- }
171
- deactivate() {
172
- if (this._observer) {
173
- this._observer.disconnect();
174
- this._observer = null;
175
- }
176
- this._nodes.forEach(node => {
177
- node.removeAttribute('aria-hidden');
178
- });
179
- this._nodes = [];
180
- this._attributes.forEach(attribute => {
181
- attribute[0].setAttribute(attribute[1], attribute[2] || '');
182
- });
183
- this._attributes = [];
184
- this._parents = [];
185
- }
186
- }
187
- exports.ScreenReaderFocusRegion = ScreenReaderFocusRegion;
188
- var _default = exports.default = ScreenReaderFocusRegion;
package/lib/index.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "FocusRegion", {
7
- enumerable: true,
8
- get: function () {
9
- return _FocusRegion.FocusRegion;
10
- }
11
- });
12
- Object.defineProperty(exports, "FocusRegionManager", {
13
- enumerable: true,
14
- get: function () {
15
- return _FocusRegionManager.FocusRegionManager;
16
- }
17
- });
18
- Object.defineProperty(exports, "KeyboardFocusRegion", {
19
- enumerable: true,
20
- get: function () {
21
- return _KeyboardFocusRegion.KeyboardFocusRegion;
22
- }
23
- });
24
- Object.defineProperty(exports, "ScreenReaderFocusRegion", {
25
- enumerable: true,
26
- get: function () {
27
- return _ScreenReaderFocusRegion.ScreenReaderFocusRegion;
28
- }
29
- });
30
- Object.defineProperty(exports, "hasVisibleChildren", {
31
- enumerable: true,
32
- get: function () {
33
- return _hasVisibleChildren.hasVisibleChildren;
34
- }
35
- });
36
- Object.defineProperty(exports, "scopeTab", {
37
- enumerable: true,
38
- get: function () {
39
- return _scopeTab.scopeTab;
40
- }
41
- });
42
- var _FocusRegion = require("./FocusRegion");
43
- var _FocusRegionManager = require("./FocusRegionManager");
44
- var _hasVisibleChildren = require("./hasVisibleChildren");
45
- var _KeyboardFocusRegion = require("./KeyboardFocusRegion");
46
- var _scopeTab = require("./scopeTab");
47
- var _ScreenReaderFocusRegion = require("./ScreenReaderFocusRegion");
package/lib/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
package/lib/scopeTab.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.scopeTab = scopeTab;
8
- var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
9
- var _findTabbable = require("@instructure/ui-dom-utils/lib/findTabbable.js");
10
- var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
11
- var _containsActiveElement = require("@instructure/ui-dom-utils/lib/containsActiveElement.js");
12
- /*
13
- * The MIT License (MIT)
14
- *
15
- * Copyright (c) 2015 - present Instructure, Inc.
16
- *
17
- * Permission is hereby granted, free of charge, to any person obtaining a copy
18
- * of this software and associated documentation files (the "Software"), to deal
19
- * in the Software without restriction, including without limitation the rights
20
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- * copies of the Software, and to permit persons to whom the Software is
22
- * furnished to do so, subject to the following conditions:
23
- *
24
- * The above copyright notice and this permission notice shall be included in all
25
- * copies or substantial portions of the Software.
26
- *
27
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- * SOFTWARE.
34
- */
35
-
36
- /**
37
- * ---
38
- * category: utilities/a11y
39
- * ---
40
- *
41
- * Scope tab in order to trap focus within a specified
42
- * element.
43
- * @module scopeTab
44
- * @param element
45
- * @param event the DOM Event that was fired
46
- * @param onLeavingFinalTabbable function executed when leaving final tabbable instead of the default behavior
47
- */
48
- function scopeTab(element, event, onLeavingFinalTabbable) {
49
- const node = (0, _findDOMNode.findDOMNode)(element);
50
- const tabbable = (0, _findTabbable.findTabbable)(node);
51
- if (!tabbable.length) {
52
- event.preventDefault();
53
- return;
54
- }
55
- const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
56
- const leavingFinalTabbable =
57
- // This can happen in Menu, where the first menu item becomes unfocusable
58
- // when its focused and tab is pressed, leaving one element
59
- // (the menu container) in the tabbable array, which is not the currently
60
- // active element
61
- tabbable.length < 2 || (0, _isActiveElement.isActiveElement)(finalTabbable) ||
62
- // handle immediate shift+tab after opening with mouse
63
- (0, _isActiveElement.isActiveElement)(node) ||
64
- // already left final tabbable
65
- !(0, _containsActiveElement.containsActiveElement)(element);
66
- if (!leavingFinalTabbable) return;
67
- if (typeof onLeavingFinalTabbable === 'function') {
68
- onLeavingFinalTabbable();
69
- return;
70
- }
71
- event.preventDefault();
72
- const target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];
73
- target.focus();
74
- }
75
- var _default = exports.default = scopeTab;
package/lib/types.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });