@instructure/ui-a11y-utils 8.25.1-snapshot-10 → 8.25.1-snapshot-15

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,7 +3,7 @@
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
- ## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
6
+ ## [8.25.1-snapshot-15](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-15) (2022-06-23)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-a11y-utils
9
9
 
package/es/FocusRegion.js CHANGED
@@ -29,16 +29,46 @@ import { ScreenReaderFocusRegion } from './ScreenReaderFocusRegion';
29
29
  import { KeyboardFocusRegion } from './KeyboardFocusRegion';
30
30
 
31
31
  class FocusRegion {
32
- _contextElement = null;
33
- _preventCloseOnDocumentClick = false;
34
- _options;
35
- _screenReaderFocusRegion;
36
- _keyboardFocusRegion;
37
- _id;
38
- _listeners = [];
39
- _active = false;
40
-
41
32
  constructor(element, options) {
33
+ this._contextElement = null;
34
+ this._preventCloseOnDocumentClick = false;
35
+ this._options = void 0;
36
+ this._screenReaderFocusRegion = void 0;
37
+ this._keyboardFocusRegion = void 0;
38
+ this._id = void 0;
39
+ this._listeners = [];
40
+ this._active = false;
41
+
42
+ this.handleDismiss = (event, documentClick) => {
43
+ var _this$_options$onDism, _this$_options;
44
+
45
+ (_this$_options$onDism = (_this$_options = this._options).onDismiss) === null || _this$_options$onDism === void 0 ? void 0 : _this$_options$onDism.call(_this$_options, event, documentClick);
46
+ };
47
+
48
+ this.captureDocumentClick = event => {
49
+ const target = event.target;
50
+ this._preventCloseOnDocumentClick = event.button !== 0 || contains(this._contextElement, target);
51
+ };
52
+
53
+ this.handleDocumentClick = event => {
54
+ if (this._options.shouldCloseOnDocumentClick && !this._preventCloseOnDocumentClick) {
55
+ this.handleDismiss(event, true);
56
+ }
57
+ };
58
+
59
+ this.handleFrameClick = (event, frame) => {
60
+ if (!contains(this._contextElement, frame)) {
61
+ // dismiss if frame is not within the region
62
+ this.handleDismiss(event, true);
63
+ }
64
+ };
65
+
66
+ this.handleKeyUp = event => {
67
+ if (this._options.shouldCloseOnEscape && event.keyCode === keycode.codes.esc && !event.defaultPrevented) {
68
+ this.handleDismiss(event);
69
+ }
70
+ };
71
+
42
72
  this._options = options || {
43
73
  shouldCloseOnDocumentClick: true,
44
74
  shouldCloseOnEscape: true
@@ -65,32 +95,6 @@ class FocusRegion {
65
95
  }
66
96
  }
67
97
 
68
- handleDismiss = (event, documentClick) => {
69
- var _this$_options$onDism, _this$_options;
70
-
71
- (_this$_options$onDism = (_this$_options = this._options).onDismiss) === null || _this$_options$onDism === void 0 ? void 0 : _this$_options$onDism.call(_this$_options, event, documentClick);
72
- };
73
- captureDocumentClick = event => {
74
- const target = event.target;
75
- this._preventCloseOnDocumentClick = event.button !== 0 || contains(this._contextElement, target);
76
- };
77
- handleDocumentClick = event => {
78
- if (this._options.shouldCloseOnDocumentClick && !this._preventCloseOnDocumentClick) {
79
- this.handleDismiss(event, true);
80
- }
81
- };
82
- handleFrameClick = (event, frame) => {
83
- if (!contains(this._contextElement, frame)) {
84
- // dismiss if frame is not within the region
85
- this.handleDismiss(event, true);
86
- }
87
- };
88
- handleKeyUp = event => {
89
- if (this._options.shouldCloseOnEscape && event.keyCode === keycode.codes.esc && !event.defaultPrevented) {
90
- this.handleDismiss(event);
91
- }
92
- };
93
-
94
98
  get id() {
95
99
  return this._id;
96
100
  } // Focused returns when the focus region is active. Checking focused with the active element
@@ -25,138 +25,147 @@ import { logError as error } from '@instructure/console';
25
25
  import { FocusRegion } from './FocusRegion';
26
26
  let ENTRIES = [];
27
27
 
28
- class FocusRegionManager {
29
- static focusRegion = function (element) {
30
- let idOrOptions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
31
- let entry;
32
-
33
- if (typeof idOrOptions === 'string') {
34
- entry = FocusRegionManager.getEntry(element, idOrOptions);
35
- } else {
36
- entry = FocusRegionManager.addEntry(element, idOrOptions);
28
+ class FocusRegionManager {}
29
+
30
+ FocusRegionManager.focusRegion = function (element) {
31
+ let idOrOptions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
32
+ let entry;
33
+
34
+ if (typeof idOrOptions === 'string') {
35
+ entry = FocusRegionManager.getEntry(element, idOrOptions);
36
+ } else {
37
+ entry = FocusRegionManager.addEntry(element, idOrOptions);
38
+ }
39
+
40
+ if (entry && entry.region && typeof entry.region.focus === 'function') {
41
+ entry.region.focus();
42
+ return entry.region;
43
+ } else {
44
+ error(false, `[FocusRegionManager] Could not focus region with element: ${element}`);
45
+ }
46
+
47
+ return;
48
+ };
49
+
50
+ FocusRegionManager.activateRegion = (element, options) => {
51
+ const _FocusRegionManager$a = FocusRegionManager.addEntry(element, options),
52
+ region = _FocusRegionManager$a.region;
53
+
54
+ return region;
55
+ };
56
+
57
+ FocusRegionManager.getActiveEntry = () => {
58
+ return ENTRIES.find(_ref => {
59
+ let region = _ref.region;
60
+ return region.focused;
61
+ });
62
+ };
63
+
64
+ FocusRegionManager.findEntry = (element, id) => {
65
+ let index;
66
+
67
+ if (id) {
68
+ index = ENTRIES.findIndex(entry => entry.id === id);
69
+ } else {
70
+ index = ENTRIES.findIndex(entry => entry.element === element);
71
+ }
72
+
73
+ return index;
74
+ };
75
+
76
+ FocusRegionManager.getEntry = (element, id) => {
77
+ return ENTRIES[FocusRegionManager.findEntry(element, id)];
78
+ };
79
+
80
+ FocusRegionManager.addEntry = function (element) {
81
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
82
+ const region = new FocusRegion(element, options);
83
+ const activeEntry = FocusRegionManager.getActiveEntry();
84
+ const keyboardFocusable = region.keyboardFocusable;
85
+ ENTRIES.forEach(_ref2 => {
86
+ let region = _ref2.region;
87
+
88
+ if (region) {
89
+ // If the active region is triggering a new focus region that does not have
90
+ // keyboard focusable content, don't deactivate the active region's keyboard
91
+ // focus region
92
+ const keyboard = region.focused && !keyboardFocusable ? {
93
+ keyboard: false
94
+ } : void 0;
95
+ region.deactivate(keyboard);
37
96
  }
38
-
39
- if (entry && entry.region && typeof entry.region.focus === 'function') {
40
- entry.region.focus();
41
- return entry.region;
42
- } else {
43
- error(false, `[FocusRegionManager] Could not focus region with element: ${element}`);
44
- }
45
-
46
- return;
97
+ });
98
+ region.activate();
99
+
100
+ if (options.shouldFocusOnOpen) {
101
+ region.focus();
102
+ }
103
+
104
+ const entry = {
105
+ id: region.id,
106
+ element,
107
+ region,
108
+ children: [],
109
+ parent: activeEntry
47
110
  };
48
- static activateRegion = (element, options) => {
49
- const _FocusRegionManager$a = FocusRegionManager.addEntry(element, options),
50
- region = _FocusRegionManager$a.region;
111
+ ENTRIES.push(entry);
51
112
 
52
- return region;
53
- };
54
- static getActiveEntry = () => {
55
- return ENTRIES.find(_ref => {
56
- let region = _ref.region;
57
- return region.focused;
58
- });
59
- };
60
- static findEntry = (element, id) => {
61
- let index;
113
+ if (activeEntry) {
114
+ activeEntry.children.push(entry);
115
+ }
62
116
 
63
- if (id) {
64
- index = ENTRIES.findIndex(entry => entry.id === id);
65
- } else {
66
- index = ENTRIES.findIndex(entry => entry.element === element);
67
- }
117
+ return entry;
118
+ };
68
119
 
69
- return index;
70
- };
71
- static getEntry = (element, id) => {
72
- return ENTRIES[FocusRegionManager.findEntry(element, id)];
73
- };
74
- static addEntry = function (element) {
75
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
76
- const region = new FocusRegion(element, options);
77
- const activeEntry = FocusRegionManager.getActiveEntry();
78
- const keyboardFocusable = region.keyboardFocusable;
79
- ENTRIES.forEach(_ref2 => {
80
- let region = _ref2.region;
81
-
82
- if (region) {
83
- // If the active region is triggering a new focus region that does not have
84
- // keyboard focusable content, don't deactivate the active region's keyboard
85
- // focus region
86
- const keyboard = region.focused && !keyboardFocusable ? {
87
- keyboard: false
88
- } : void 0;
89
- region.deactivate(keyboard);
90
- }
91
- });
92
- region.activate();
93
-
94
- if (options.shouldFocusOnOpen) {
95
- region.focus();
96
- }
120
+ FocusRegionManager.removeEntry = (element, id) => {
121
+ const index = FocusRegionManager.findEntry(element, id);
122
+ const entry = ENTRIES[index];
97
123
 
98
- const entry = {
99
- id: region.id,
100
- element,
101
- region,
102
- children: [],
103
- parent: activeEntry
104
- };
105
- ENTRIES.push(entry);
106
-
107
- if (activeEntry) {
108
- activeEntry.children.push(entry);
109
- }
124
+ if (index > -1) {
125
+ ENTRIES.splice(index, 1);
126
+ }
110
127
 
111
- return entry;
112
- };
113
- static removeEntry = (element, id) => {
114
- const index = FocusRegionManager.findEntry(element, id);
115
- const entry = ENTRIES[index];
128
+ return entry;
129
+ };
116
130
 
117
- if (index > -1) {
118
- ENTRIES.splice(index, 1);
119
- }
131
+ FocusRegionManager.isFocused = (element, id) => {
132
+ const entry = FocusRegionManager.getActiveEntry();
120
133
 
121
- return entry;
122
- };
123
- static isFocused = (element, id) => {
124
- const entry = FocusRegionManager.getActiveEntry();
134
+ if (id) {
135
+ return entry && entry.region && entry.id === id;
136
+ } else {
137
+ return entry && entry.region && entry.element === element;
138
+ }
139
+ };
125
140
 
126
- if (id) {
127
- return entry && entry.region && entry.id === id;
128
- } else {
129
- return entry && entry.region && entry.element === element;
130
- }
131
- };
132
- static clearEntries = () => {
133
- ENTRIES = [];
134
- };
135
- static blurRegion = (element, id) => {
136
- const entry = FocusRegionManager.removeEntry(element, id);
141
+ FocusRegionManager.clearEntries = () => {
142
+ ENTRIES = [];
143
+ };
137
144
 
138
- if (entry) {
139
- const children = entry.children,
140
- region = entry.region,
141
- parent = entry.parent; // deactivate the region...
145
+ FocusRegionManager.blurRegion = (element, id) => {
146
+ const entry = FocusRegionManager.removeEntry(element, id);
142
147
 
143
- region && region.deactivate(); // and any regions created from it
148
+ if (entry) {
149
+ const children = entry.children,
150
+ region = entry.region,
151
+ parent = entry.parent; // deactivate the region...
144
152
 
145
- if (children) {
146
- children.forEach(_ref3 => {
147
- let id = _ref3.id,
148
- element = _ref3.element;
149
- const entry = FocusRegionManager.removeEntry(element, id);
150
- entry && entry.region && entry.region.deactivate();
151
- });
152
- } // activate the region's parent if it exists
153
+ region && region.deactivate(); // and any regions created from it
153
154
 
155
+ if (children) {
156
+ children.forEach(_ref3 => {
157
+ let id = _ref3.id,
158
+ element = _ref3.element;
159
+ const entry = FocusRegionManager.removeEntry(element, id);
160
+ entry && entry.region && entry.region.deactivate();
161
+ });
162
+ } // activate the region's parent if it exists
154
163
 
155
- parent && parent.region && parent.region.activate();
156
- region && region.blur(); // this should focus the parent region
157
- }
158
- };
159
- }
164
+
165
+ parent && parent.region && parent.region.activate();
166
+ region && region.blur(); // this should focus the parent region
167
+ }
168
+ };
160
169
 
161
170
  export default FocusRegionManager;
162
171
  export {
@@ -27,16 +27,74 @@ import keycode from 'keycode';
27
27
  import { scopeTab } from './scopeTab';
28
28
 
29
29
  class KeyboardFocusRegion {
30
- _options;
31
- _focusLaterElement = null;
32
- _needToFocus = false;
33
- _listeners = [];
34
- _raf = [];
35
- _active = false;
36
- _wasDocumentClick;
37
- _contextElement;
38
-
39
30
  constructor(element, options) {
31
+ this._options = void 0;
32
+ this._focusLaterElement = null;
33
+ this._needToFocus = false;
34
+ this._listeners = [];
35
+ this._raf = [];
36
+ this._active = false;
37
+ this._wasDocumentClick = void 0;
38
+ this._contextElement = void 0;
39
+
40
+ this.handleKeyDown = event => {
41
+ if (event.keyCode === keycode.codes.tab) {
42
+ scopeTab(this._contextElement, event);
43
+ }
44
+ };
45
+
46
+ this.handleClick = () => {
47
+ this._wasDocumentClick = true;
48
+ };
49
+
50
+ this.handleWindowBlur = () => {
51
+ if (this._wasDocumentClick) {
52
+ this._wasDocumentClick = false;
53
+ return;
54
+ }
55
+
56
+ this._needToFocus = true;
57
+ };
58
+
59
+ this.handleFocus = () => {
60
+ if (this._needToFocus) {
61
+ this._needToFocus = false;
62
+
63
+ if (!this._contextElement) {
64
+ return;
65
+ } // need to see how jQuery shims document.on('focusin') so we don't need the
66
+ // setTimeout, firefox doesn't support focusin, if it did, we could focus
67
+ // the element outside of a setTimeout. Side-effect of this implementation
68
+ // is that the document.body gets focus, and then we focus our element right
69
+ // after, seems fine.
70
+
71
+
72
+ this._raf.push(requestAnimationFrame(() => {
73
+ if (containsActiveElement(this._contextElement)) {
74
+ return;
75
+ }
76
+
77
+ this.focusDefaultElement();
78
+ }));
79
+ }
80
+ };
81
+
82
+ this.handleFirstTabbableKeyDown = event => {
83
+ if (event.keyCode === keycode.codes.tab && event.shiftKey) {
84
+ var _this$_options$onBlur, _this$_options;
85
+
86
+ (_this$_options$onBlur = (_this$_options = this._options).onBlur) === null || _this$_options$onBlur === void 0 ? void 0 : _this$_options$onBlur.call(_this$_options, event);
87
+ }
88
+ };
89
+
90
+ this.handleLastTabbableKeyDown = event => {
91
+ if (event.keyCode === keycode.codes.tab && !event.shiftKey) {
92
+ var _this$_options$onBlur2, _this$_options2;
93
+
94
+ (_this$_options$onBlur2 = (_this$_options2 = this._options).onBlur) === null || _this$_options$onBlur2 === void 0 ? void 0 : _this$_options$onBlur2.call(_this$_options2, event);
95
+ }
96
+ };
97
+
40
98
  this._contextElement = findDOMNode(element);
41
99
  this._options = options || {
42
100
  shouldContainFocus: true,
@@ -156,59 +214,6 @@ class KeyboardFocusRegion {
156
214
  }
157
215
  }
158
216
 
159
- handleKeyDown = event => {
160
- if (event.keyCode === keycode.codes.tab) {
161
- scopeTab(this._contextElement, event);
162
- }
163
- };
164
- handleClick = () => {
165
- this._wasDocumentClick = true;
166
- };
167
- handleWindowBlur = () => {
168
- if (this._wasDocumentClick) {
169
- this._wasDocumentClick = false;
170
- return;
171
- }
172
-
173
- this._needToFocus = true;
174
- };
175
- handleFocus = () => {
176
- if (this._needToFocus) {
177
- this._needToFocus = false;
178
-
179
- if (!this._contextElement) {
180
- return;
181
- } // need to see how jQuery shims document.on('focusin') so we don't need the
182
- // setTimeout, firefox doesn't support focusin, if it did, we could focus
183
- // the element outside of a setTimeout. Side-effect of this implementation
184
- // is that the document.body gets focus, and then we focus our element right
185
- // after, seems fine.
186
-
187
-
188
- this._raf.push(requestAnimationFrame(() => {
189
- if (containsActiveElement(this._contextElement)) {
190
- return;
191
- }
192
-
193
- this.focusDefaultElement();
194
- }));
195
- }
196
- };
197
- handleFirstTabbableKeyDown = event => {
198
- if (event.keyCode === keycode.codes.tab && event.shiftKey) {
199
- var _this$_options$onBlur, _this$_options;
200
-
201
- (_this$_options$onBlur = (_this$_options = this._options).onBlur) === null || _this$_options$onBlur === void 0 ? void 0 : _this$_options$onBlur.call(_this$_options, event);
202
- }
203
- };
204
- handleLastTabbableKeyDown = event => {
205
- if (event.keyCode === keycode.codes.tab && !event.shiftKey) {
206
- var _this$_options$onBlur2, _this$_options2;
207
-
208
- (_this$_options$onBlur2 = (_this$_options2 = this._options).onBlur) === null || _this$_options$onBlur2 === void 0 ? void 0 : _this$_options$onBlur2.call(_this$_options2, event);
209
- }
210
- };
211
-
212
217
  activate() {
213
218
  const defaultFocusElement = this.defaultFocusElement,
214
219
  shouldContainFocus = this.shouldContainFocus;
@@ -24,19 +24,39 @@
24
24
  import { logWarn as warn } from '@instructure/console';
25
25
 
26
26
  class ScreenReaderFocusRegion {
27
- _parents = [];
28
- _nodes = [];
29
- _liveRegion;
30
- _contextElement;
31
- _options;
32
- _observer = null;
33
- _attributes = [];
34
-
35
27
  constructor(element) {
36
28
  let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
37
29
  shouldContainFocus: true,
38
30
  liveRegion: []
39
31
  };
32
+ this._parents = [];
33
+ this._nodes = [];
34
+ this._liveRegion = void 0;
35
+ this._contextElement = void 0;
36
+ this._options = void 0;
37
+ this._observer = null;
38
+ this._attributes = [];
39
+
40
+ this.handleDOMMutation = records => {
41
+ records.forEach(record => {
42
+ const addedNodes = Array.from(record.addedNodes);
43
+ const removedNodes = Array.from(record.removedNodes);
44
+ this.hideNodes(addedNodes);
45
+ removedNodes.forEach(removedNode => {
46
+ // Node has been removed from the DOM, make sure it is
47
+ // removed from our list of hidden nodes as well
48
+ if (removedNode.tagName.toLowerCase() !== 'iframe') {
49
+ this.restoreNode(removedNode);
50
+ }
51
+
52
+ const iframeBodies = this.parseIframeBodies(removedNode);
53
+ iframeBodies.forEach(iframeBody => {
54
+ this.restoreNode(iframeBody);
55
+ });
56
+ });
57
+ });
58
+ };
59
+
40
60
  const liveRegion = typeof options.liveRegion === 'function' ? options.liveRegion() : options.liveRegion;
41
61
  this._liveRegion = Array.isArray(liveRegion) ? liveRegion : [liveRegion];
42
62
  this._contextElement = element;
@@ -100,26 +120,6 @@ class ScreenReaderFocusRegion {
100
120
  }
101
121
  }
102
122
 
103
- handleDOMMutation = records => {
104
- records.forEach(record => {
105
- const addedNodes = Array.from(record.addedNodes);
106
- const removedNodes = Array.from(record.removedNodes);
107
- this.hideNodes(addedNodes);
108
- removedNodes.forEach(removedNode => {
109
- // Node has been removed from the DOM, make sure it is
110
- // removed from our list of hidden nodes as well
111
- if (removedNode.tagName.toLowerCase() !== 'iframe') {
112
- this.restoreNode(removedNode);
113
- }
114
-
115
- const iframeBodies = this.parseIframeBodies(removedNode);
116
- iframeBodies.forEach(iframeBody => {
117
- this.restoreNode(iframeBody);
118
- });
119
- });
120
- });
121
- };
122
-
123
123
  restoreNode(removedNode) {
124
124
  const index = this._nodes.indexOf(removedNode);
125
125
 
@@ -49,16 +49,46 @@ var _KeyboardFocusRegion = require("./KeyboardFocusRegion");
49
49
  * SOFTWARE.
50
50
  */
51
51
  class FocusRegion {
52
- _contextElement = null;
53
- _preventCloseOnDocumentClick = false;
54
- _options;
55
- _screenReaderFocusRegion;
56
- _keyboardFocusRegion;
57
- _id;
58
- _listeners = [];
59
- _active = false;
60
-
61
52
  constructor(element, options) {
53
+ this._contextElement = null;
54
+ this._preventCloseOnDocumentClick = false;
55
+ this._options = void 0;
56
+ this._screenReaderFocusRegion = void 0;
57
+ this._keyboardFocusRegion = void 0;
58
+ this._id = void 0;
59
+ this._listeners = [];
60
+ this._active = false;
61
+
62
+ this.handleDismiss = (event, documentClick) => {
63
+ var _this$_options$onDism, _this$_options;
64
+
65
+ (_this$_options$onDism = (_this$_options = this._options).onDismiss) === null || _this$_options$onDism === void 0 ? void 0 : _this$_options$onDism.call(_this$_options, event, documentClick);
66
+ };
67
+
68
+ this.captureDocumentClick = event => {
69
+ const target = event.target;
70
+ this._preventCloseOnDocumentClick = event.button !== 0 || (0, _contains.contains)(this._contextElement, target);
71
+ };
72
+
73
+ this.handleDocumentClick = event => {
74
+ if (this._options.shouldCloseOnDocumentClick && !this._preventCloseOnDocumentClick) {
75
+ this.handleDismiss(event, true);
76
+ }
77
+ };
78
+
79
+ this.handleFrameClick = (event, frame) => {
80
+ if (!(0, _contains.contains)(this._contextElement, frame)) {
81
+ // dismiss if frame is not within the region
82
+ this.handleDismiss(event, true);
83
+ }
84
+ };
85
+
86
+ this.handleKeyUp = event => {
87
+ if (this._options.shouldCloseOnEscape && event.keyCode === _keycode.default.codes.esc && !event.defaultPrevented) {
88
+ this.handleDismiss(event);
89
+ }
90
+ };
91
+
62
92
  this._options = options || {
63
93
  shouldCloseOnDocumentClick: true,
64
94
  shouldCloseOnEscape: true
@@ -85,32 +115,6 @@ class FocusRegion {
85
115
  }
86
116
  }
87
117
 
88
- handleDismiss = (event, documentClick) => {
89
- var _this$_options$onDism, _this$_options;
90
-
91
- (_this$_options$onDism = (_this$_options = this._options).onDismiss) === null || _this$_options$onDism === void 0 ? void 0 : _this$_options$onDism.call(_this$_options, event, documentClick);
92
- };
93
- captureDocumentClick = event => {
94
- const target = event.target;
95
- this._preventCloseOnDocumentClick = event.button !== 0 || (0, _contains.contains)(this._contextElement, target);
96
- };
97
- handleDocumentClick = event => {
98
- if (this._options.shouldCloseOnDocumentClick && !this._preventCloseOnDocumentClick) {
99
- this.handleDismiss(event, true);
100
- }
101
- };
102
- handleFrameClick = (event, frame) => {
103
- if (!(0, _contains.contains)(this._contextElement, frame)) {
104
- // dismiss if frame is not within the region
105
- this.handleDismiss(event, true);
106
- }
107
- };
108
- handleKeyUp = event => {
109
- if (this._options.shouldCloseOnEscape && event.keyCode === _keycode.default.codes.esc && !event.defaultPrevented) {
110
- this.handleDismiss(event);
111
- }
112
- };
113
-
114
118
  get id() {
115
119
  return this._id;
116
120
  } // Focused returns when the focus region is active. Checking focused with the active element
@@ -34,139 +34,149 @@ var _FocusRegion = require("./FocusRegion");
34
34
  */
35
35
  let ENTRIES = [];
36
36
 
37
- class FocusRegionManager {
38
- static focusRegion = function (element) {
39
- let idOrOptions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
40
- let entry;
41
-
42
- if (typeof idOrOptions === 'string') {
43
- entry = FocusRegionManager.getEntry(element, idOrOptions);
44
- } else {
45
- entry = FocusRegionManager.addEntry(element, idOrOptions);
46
- }
37
+ class FocusRegionManager {}
47
38
 
48
- if (entry && entry.region && typeof entry.region.focus === 'function') {
49
- entry.region.focus();
50
- return entry.region;
51
- } else {
52
- (0, _console.logError)(false, `[FocusRegionManager] Could not focus region with element: ${element}`);
53
- }
39
+ exports.FocusRegionManager = FocusRegionManager;
54
40
 
55
- return;
41
+ FocusRegionManager.focusRegion = function (element) {
42
+ let idOrOptions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
43
+ let entry;
44
+
45
+ if (typeof idOrOptions === 'string') {
46
+ entry = FocusRegionManager.getEntry(element, idOrOptions);
47
+ } else {
48
+ entry = FocusRegionManager.addEntry(element, idOrOptions);
49
+ }
50
+
51
+ if (entry && entry.region && typeof entry.region.focus === 'function') {
52
+ entry.region.focus();
53
+ return entry.region;
54
+ } else {
55
+ (0, _console.logError)(false, `[FocusRegionManager] Could not focus region with element: ${element}`);
56
+ }
57
+
58
+ return;
59
+ };
60
+
61
+ FocusRegionManager.activateRegion = (element, options) => {
62
+ const _FocusRegionManager$a = FocusRegionManager.addEntry(element, options),
63
+ region = _FocusRegionManager$a.region;
64
+
65
+ return region;
66
+ };
67
+
68
+ FocusRegionManager.getActiveEntry = () => {
69
+ return ENTRIES.find(_ref => {
70
+ let region = _ref.region;
71
+ return region.focused;
72
+ });
73
+ };
74
+
75
+ FocusRegionManager.findEntry = (element, id) => {
76
+ let index;
77
+
78
+ if (id) {
79
+ index = ENTRIES.findIndex(entry => entry.id === id);
80
+ } else {
81
+ index = ENTRIES.findIndex(entry => entry.element === element);
82
+ }
83
+
84
+ return index;
85
+ };
86
+
87
+ FocusRegionManager.getEntry = (element, id) => {
88
+ return ENTRIES[FocusRegionManager.findEntry(element, id)];
89
+ };
90
+
91
+ FocusRegionManager.addEntry = function (element) {
92
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
93
+ const region = new _FocusRegion.FocusRegion(element, options);
94
+ const activeEntry = FocusRegionManager.getActiveEntry();
95
+ const keyboardFocusable = region.keyboardFocusable;
96
+ ENTRIES.forEach(_ref2 => {
97
+ let region = _ref2.region;
98
+
99
+ if (region) {
100
+ // If the active region is triggering a new focus region that does not have
101
+ // keyboard focusable content, don't deactivate the active region's keyboard
102
+ // focus region
103
+ const keyboard = region.focused && !keyboardFocusable ? {
104
+ keyboard: false
105
+ } : void 0;
106
+ region.deactivate(keyboard);
107
+ }
108
+ });
109
+ region.activate();
110
+
111
+ if (options.shouldFocusOnOpen) {
112
+ region.focus();
113
+ }
114
+
115
+ const entry = {
116
+ id: region.id,
117
+ element,
118
+ region,
119
+ children: [],
120
+ parent: activeEntry
56
121
  };
57
- static activateRegion = (element, options) => {
58
- const _FocusRegionManager$a = FocusRegionManager.addEntry(element, options),
59
- region = _FocusRegionManager$a.region;
122
+ ENTRIES.push(entry);
60
123
 
61
- return region;
62
- };
63
- static getActiveEntry = () => {
64
- return ENTRIES.find(_ref => {
65
- let region = _ref.region;
66
- return region.focused;
67
- });
68
- };
69
- static findEntry = (element, id) => {
70
- let index;
124
+ if (activeEntry) {
125
+ activeEntry.children.push(entry);
126
+ }
71
127
 
72
- if (id) {
73
- index = ENTRIES.findIndex(entry => entry.id === id);
74
- } else {
75
- index = ENTRIES.findIndex(entry => entry.element === element);
76
- }
128
+ return entry;
129
+ };
77
130
 
78
- return index;
79
- };
80
- static getEntry = (element, id) => {
81
- return ENTRIES[FocusRegionManager.findEntry(element, id)];
82
- };
83
- static addEntry = function (element) {
84
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
85
- const region = new _FocusRegion.FocusRegion(element, options);
86
- const activeEntry = FocusRegionManager.getActiveEntry();
87
- const keyboardFocusable = region.keyboardFocusable;
88
- ENTRIES.forEach(_ref2 => {
89
- let region = _ref2.region;
90
-
91
- if (region) {
92
- // If the active region is triggering a new focus region that does not have
93
- // keyboard focusable content, don't deactivate the active region's keyboard
94
- // focus region
95
- const keyboard = region.focused && !keyboardFocusable ? {
96
- keyboard: false
97
- } : void 0;
98
- region.deactivate(keyboard);
99
- }
100
- });
101
- region.activate();
102
-
103
- if (options.shouldFocusOnOpen) {
104
- region.focus();
105
- }
131
+ FocusRegionManager.removeEntry = (element, id) => {
132
+ const index = FocusRegionManager.findEntry(element, id);
133
+ const entry = ENTRIES[index];
106
134
 
107
- const entry = {
108
- id: region.id,
109
- element,
110
- region,
111
- children: [],
112
- parent: activeEntry
113
- };
114
- ENTRIES.push(entry);
115
-
116
- if (activeEntry) {
117
- activeEntry.children.push(entry);
118
- }
135
+ if (index > -1) {
136
+ ENTRIES.splice(index, 1);
137
+ }
119
138
 
120
- return entry;
121
- };
122
- static removeEntry = (element, id) => {
123
- const index = FocusRegionManager.findEntry(element, id);
124
- const entry = ENTRIES[index];
139
+ return entry;
140
+ };
125
141
 
126
- if (index > -1) {
127
- ENTRIES.splice(index, 1);
128
- }
142
+ FocusRegionManager.isFocused = (element, id) => {
143
+ const entry = FocusRegionManager.getActiveEntry();
129
144
 
130
- return entry;
131
- };
132
- static isFocused = (element, id) => {
133
- const entry = FocusRegionManager.getActiveEntry();
145
+ if (id) {
146
+ return entry && entry.region && entry.id === id;
147
+ } else {
148
+ return entry && entry.region && entry.element === element;
149
+ }
150
+ };
134
151
 
135
- if (id) {
136
- return entry && entry.region && entry.id === id;
137
- } else {
138
- return entry && entry.region && entry.element === element;
139
- }
140
- };
141
- static clearEntries = () => {
142
- ENTRIES = [];
143
- };
144
- static blurRegion = (element, id) => {
145
- const entry = FocusRegionManager.removeEntry(element, id);
152
+ FocusRegionManager.clearEntries = () => {
153
+ ENTRIES = [];
154
+ };
146
155
 
147
- if (entry) {
148
- const children = entry.children,
149
- region = entry.region,
150
- parent = entry.parent; // deactivate the region...
156
+ FocusRegionManager.blurRegion = (element, id) => {
157
+ const entry = FocusRegionManager.removeEntry(element, id);
151
158
 
152
- region && region.deactivate(); // and any regions created from it
159
+ if (entry) {
160
+ const children = entry.children,
161
+ region = entry.region,
162
+ parent = entry.parent; // deactivate the region...
153
163
 
154
- if (children) {
155
- children.forEach(_ref3 => {
156
- let id = _ref3.id,
157
- element = _ref3.element;
158
- const entry = FocusRegionManager.removeEntry(element, id);
159
- entry && entry.region && entry.region.deactivate();
160
- });
161
- } // activate the region's parent if it exists
164
+ region && region.deactivate(); // and any regions created from it
162
165
 
166
+ if (children) {
167
+ children.forEach(_ref3 => {
168
+ let id = _ref3.id,
169
+ element = _ref3.element;
170
+ const entry = FocusRegionManager.removeEntry(element, id);
171
+ entry && entry.region && entry.region.deactivate();
172
+ });
173
+ } // activate the region's parent if it exists
163
174
 
164
- parent && parent.region && parent.region.activate();
165
- region && region.blur(); // this should focus the parent region
166
- }
167
- };
168
- }
169
175
 
170
- exports.FocusRegionManager = FocusRegionManager;
176
+ parent && parent.region && parent.region.activate();
177
+ region && region.blur(); // this should focus the parent region
178
+ }
179
+ };
180
+
171
181
  var _default = FocusRegionManager;
172
182
  exports.default = _default;
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -55,16 +55,74 @@ var _scopeTab = require("./scopeTab");
55
55
  * SOFTWARE.
56
56
  */
57
57
  class KeyboardFocusRegion {
58
- _options;
59
- _focusLaterElement = null;
60
- _needToFocus = false;
61
- _listeners = [];
62
- _raf = [];
63
- _active = false;
64
- _wasDocumentClick;
65
- _contextElement;
66
-
67
58
  constructor(element, options) {
59
+ this._options = void 0;
60
+ this._focusLaterElement = null;
61
+ this._needToFocus = false;
62
+ this._listeners = [];
63
+ this._raf = [];
64
+ this._active = false;
65
+ this._wasDocumentClick = void 0;
66
+ this._contextElement = void 0;
67
+
68
+ this.handleKeyDown = event => {
69
+ if (event.keyCode === _keycode.default.codes.tab) {
70
+ (0, _scopeTab.scopeTab)(this._contextElement, event);
71
+ }
72
+ };
73
+
74
+ this.handleClick = () => {
75
+ this._wasDocumentClick = true;
76
+ };
77
+
78
+ this.handleWindowBlur = () => {
79
+ if (this._wasDocumentClick) {
80
+ this._wasDocumentClick = false;
81
+ return;
82
+ }
83
+
84
+ this._needToFocus = true;
85
+ };
86
+
87
+ this.handleFocus = () => {
88
+ if (this._needToFocus) {
89
+ this._needToFocus = false;
90
+
91
+ if (!this._contextElement) {
92
+ return;
93
+ } // need to see how jQuery shims document.on('focusin') so we don't need the
94
+ // setTimeout, firefox doesn't support focusin, if it did, we could focus
95
+ // the element outside of a setTimeout. Side-effect of this implementation
96
+ // is that the document.body gets focus, and then we focus our element right
97
+ // after, seems fine.
98
+
99
+
100
+ this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(() => {
101
+ if ((0, _containsActiveElement.containsActiveElement)(this._contextElement)) {
102
+ return;
103
+ }
104
+
105
+ this.focusDefaultElement();
106
+ }));
107
+ }
108
+ };
109
+
110
+ this.handleFirstTabbableKeyDown = event => {
111
+ if (event.keyCode === _keycode.default.codes.tab && event.shiftKey) {
112
+ var _this$_options$onBlur, _this$_options;
113
+
114
+ (_this$_options$onBlur = (_this$_options = this._options).onBlur) === null || _this$_options$onBlur === void 0 ? void 0 : _this$_options$onBlur.call(_this$_options, event);
115
+ }
116
+ };
117
+
118
+ this.handleLastTabbableKeyDown = event => {
119
+ if (event.keyCode === _keycode.default.codes.tab && !event.shiftKey) {
120
+ var _this$_options$onBlur2, _this$_options2;
121
+
122
+ (_this$_options$onBlur2 = (_this$_options2 = this._options).onBlur) === null || _this$_options$onBlur2 === void 0 ? void 0 : _this$_options$onBlur2.call(_this$_options2, event);
123
+ }
124
+ };
125
+
68
126
  this._contextElement = (0, _findDOMNode.findDOMNode)(element);
69
127
  this._options = options || {
70
128
  shouldContainFocus: true,
@@ -184,59 +242,6 @@ class KeyboardFocusRegion {
184
242
  }
185
243
  }
186
244
 
187
- handleKeyDown = event => {
188
- if (event.keyCode === _keycode.default.codes.tab) {
189
- (0, _scopeTab.scopeTab)(this._contextElement, event);
190
- }
191
- };
192
- handleClick = () => {
193
- this._wasDocumentClick = true;
194
- };
195
- handleWindowBlur = () => {
196
- if (this._wasDocumentClick) {
197
- this._wasDocumentClick = false;
198
- return;
199
- }
200
-
201
- this._needToFocus = true;
202
- };
203
- handleFocus = () => {
204
- if (this._needToFocus) {
205
- this._needToFocus = false;
206
-
207
- if (!this._contextElement) {
208
- return;
209
- } // need to see how jQuery shims document.on('focusin') so we don't need the
210
- // setTimeout, firefox doesn't support focusin, if it did, we could focus
211
- // the element outside of a setTimeout. Side-effect of this implementation
212
- // is that the document.body gets focus, and then we focus our element right
213
- // after, seems fine.
214
-
215
-
216
- this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(() => {
217
- if ((0, _containsActiveElement.containsActiveElement)(this._contextElement)) {
218
- return;
219
- }
220
-
221
- this.focusDefaultElement();
222
- }));
223
- }
224
- };
225
- handleFirstTabbableKeyDown = event => {
226
- if (event.keyCode === _keycode.default.codes.tab && event.shiftKey) {
227
- var _this$_options$onBlur, _this$_options;
228
-
229
- (_this$_options$onBlur = (_this$_options = this._options).onBlur) === null || _this$_options$onBlur === void 0 ? void 0 : _this$_options$onBlur.call(_this$_options, event);
230
- }
231
- };
232
- handleLastTabbableKeyDown = event => {
233
- if (event.keyCode === _keycode.default.codes.tab && !event.shiftKey) {
234
- var _this$_options$onBlur2, _this$_options2;
235
-
236
- (_this$_options$onBlur2 = (_this$_options2 = this._options).onBlur) === null || _this$_options$onBlur2 === void 0 ? void 0 : _this$_options$onBlur2.call(_this$_options2, event);
237
- }
238
- };
239
-
240
245
  activate() {
241
246
  const defaultFocusElement = this.defaultFocusElement,
242
247
  shouldContainFocus = this.shouldContainFocus;
@@ -31,19 +31,39 @@ var _console = require("@instructure/console");
31
31
  * SOFTWARE.
32
32
  */
33
33
  class ScreenReaderFocusRegion {
34
- _parents = [];
35
- _nodes = [];
36
- _liveRegion;
37
- _contextElement;
38
- _options;
39
- _observer = null;
40
- _attributes = [];
41
-
42
34
  constructor(element) {
43
35
  let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
44
36
  shouldContainFocus: true,
45
37
  liveRegion: []
46
38
  };
39
+ this._parents = [];
40
+ this._nodes = [];
41
+ this._liveRegion = void 0;
42
+ this._contextElement = void 0;
43
+ this._options = void 0;
44
+ this._observer = null;
45
+ this._attributes = [];
46
+
47
+ this.handleDOMMutation = records => {
48
+ records.forEach(record => {
49
+ const addedNodes = Array.from(record.addedNodes);
50
+ const removedNodes = Array.from(record.removedNodes);
51
+ this.hideNodes(addedNodes);
52
+ removedNodes.forEach(removedNode => {
53
+ // Node has been removed from the DOM, make sure it is
54
+ // removed from our list of hidden nodes as well
55
+ if (removedNode.tagName.toLowerCase() !== 'iframe') {
56
+ this.restoreNode(removedNode);
57
+ }
58
+
59
+ const iframeBodies = this.parseIframeBodies(removedNode);
60
+ iframeBodies.forEach(iframeBody => {
61
+ this.restoreNode(iframeBody);
62
+ });
63
+ });
64
+ });
65
+ };
66
+
47
67
  const liveRegion = typeof options.liveRegion === 'function' ? options.liveRegion() : options.liveRegion;
48
68
  this._liveRegion = Array.isArray(liveRegion) ? liveRegion : [liveRegion];
49
69
  this._contextElement = element;
@@ -107,26 +127,6 @@ class ScreenReaderFocusRegion {
107
127
  }
108
128
  }
109
129
 
110
- handleDOMMutation = records => {
111
- records.forEach(record => {
112
- const addedNodes = Array.from(record.addedNodes);
113
- const removedNodes = Array.from(record.removedNodes);
114
- this.hideNodes(addedNodes);
115
- removedNodes.forEach(removedNode => {
116
- // Node has been removed from the DOM, make sure it is
117
- // removed from our list of hidden nodes as well
118
- if (removedNode.tagName.toLowerCase() !== 'iframe') {
119
- this.restoreNode(removedNode);
120
- }
121
-
122
- const iframeBodies = this.parseIframeBodies(removedNode);
123
- iframeBodies.forEach(iframeBody => {
124
- this.restoreNode(iframeBody);
125
- });
126
- });
127
- });
128
- };
129
-
130
130
  restoreNode(removedNode) {
131
131
  const index = this._nodes.indexOf(removedNode);
132
132
 
package/lib/types.js CHANGED
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-a11y-utils",
3
- "version": "8.25.1-snapshot-10",
3
+ "version": "8.25.1-snapshot-15",
4
4
  "description": "A collection of utilities for managing focus and screen reader behavior",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,19 +23,19 @@
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "@babel/runtime": "^7.13.10",
26
- "@instructure/console": "8.25.1-snapshot-10",
27
- "@instructure/ui-a11y-content": "8.25.1-snapshot-10",
28
- "@instructure/ui-dom-utils": "8.25.1-snapshot-10",
29
- "@instructure/ui-react-utils": "8.25.1-snapshot-10",
30
- "@instructure/ui-testable": "8.25.1-snapshot-10",
31
- "@instructure/uid": "8.25.1-snapshot-10",
26
+ "@instructure/console": "8.25.1-snapshot-15",
27
+ "@instructure/ui-a11y-content": "8.25.1-snapshot-15",
28
+ "@instructure/ui-dom-utils": "8.25.1-snapshot-15",
29
+ "@instructure/ui-react-utils": "8.25.1-snapshot-15",
30
+ "@instructure/ui-testable": "8.25.1-snapshot-15",
31
+ "@instructure/uid": "8.25.1-snapshot-15",
32
32
  "keycode": "^2",
33
33
  "prop-types": "^15"
34
34
  },
35
35
  "devDependencies": {
36
- "@instructure/ui-babel-preset": "8.25.1-snapshot-10",
37
- "@instructure/ui-color-utils": "8.25.1-snapshot-10",
38
- "@instructure/ui-test-utils": "8.25.1-snapshot-10"
36
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-15",
37
+ "@instructure/ui-color-utils": "8.25.1-snapshot-15",
38
+ "@instructure/ui-test-utils": "8.25.1-snapshot-15"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8 <=17"