@patternfly/react-table 4.88.1 → 4.89.1
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 +27 -0
- package/dist/umd/react-table.js +715 -155
- package/dist/umd/react-table.min.js +5 -5
- package/package.json +6 -6
- package/src/demos/Table.md +27 -11
package/dist/umd/react-table.js
CHANGED
|
@@ -130,12 +130,24 @@
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
/*!
|
|
133
|
-
* tabbable 5.
|
|
133
|
+
* tabbable 5.3.2
|
|
134
134
|
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
135
135
|
*/
|
|
136
|
-
var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', 'details>summary:first-of-type', 'details'];
|
|
136
|
+
var candidateSelectors = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]:not(slot)', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])', 'details>summary:first-of-type', 'details'];
|
|
137
137
|
var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
|
|
138
|
-
var
|
|
138
|
+
var NoElement = typeof Element === 'undefined';
|
|
139
|
+
var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
140
|
+
var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
|
|
141
|
+
return element.getRootNode();
|
|
142
|
+
} : function (element) {
|
|
143
|
+
return element.ownerDocument;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* @param {Element} el container to check in
|
|
147
|
+
* @param {boolean} includeContainer add container to check
|
|
148
|
+
* @param {(node: Element) => boolean} filter filter candidates
|
|
149
|
+
* @returns {Element[]}
|
|
150
|
+
*/
|
|
139
151
|
|
|
140
152
|
var getCandidates = function getCandidates(el, includeContainer, filter) {
|
|
141
153
|
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
|
|
@@ -147,31 +159,112 @@
|
|
|
147
159
|
candidates = candidates.filter(filter);
|
|
148
160
|
return candidates;
|
|
149
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* @callback GetShadowRoot
|
|
164
|
+
* @param {Element} element to check for shadow root
|
|
165
|
+
* @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
|
|
166
|
+
*/
|
|
150
167
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {Object} CandidatesScope
|
|
170
|
+
* @property {Element} scope contains inner candidates
|
|
171
|
+
* @property {Element[]} candidates
|
|
172
|
+
*/
|
|
154
173
|
|
|
155
|
-
|
|
156
|
-
|
|
174
|
+
/**
|
|
175
|
+
* @typedef {Object} IterativeOptions
|
|
176
|
+
* @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
|
|
177
|
+
* if a function, implies shadow support is enabled and either returns the shadow root of an element
|
|
178
|
+
* or a boolean stating if it has an undisclosed shadow root
|
|
179
|
+
* @property {(node: Element) => boolean} filter filter candidates
|
|
180
|
+
* @property {boolean} flatten if true then result will flatten any CandidatesScope into the returned list
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {Element[]} elements list of element containers to match candidates from
|
|
185
|
+
* @param {boolean} includeContainer add container list to check
|
|
186
|
+
* @param {IterativeOptions} options
|
|
187
|
+
* @returns {Array.<Element|CandidatesScope>}
|
|
188
|
+
*/
|
|
157
189
|
|
|
158
|
-
if (!isNaN(tabindexAttr)) {
|
|
159
|
-
return tabindexAttr;
|
|
160
|
-
} // Browsers do not return `tabIndex` correctly for contentEditable nodes;
|
|
161
|
-
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
162
190
|
|
|
191
|
+
var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
|
|
192
|
+
var candidates = [];
|
|
193
|
+
var elementsToCheck = Array.from(elements);
|
|
163
194
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
|
167
|
-
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
|
168
|
-
// yet they are still part of the regular tab order; in FF, they get a default
|
|
169
|
-
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
|
170
|
-
// order, consider their tab index to be 0.
|
|
195
|
+
while (elementsToCheck.length) {
|
|
196
|
+
var element = elementsToCheck.shift();
|
|
171
197
|
|
|
198
|
+
if (element.tagName === 'SLOT') {
|
|
199
|
+
// add shadow dom slot scope (slot itself cannot be focusable)
|
|
200
|
+
var assigned = element.assignedElements();
|
|
201
|
+
var content = assigned.length ? assigned : element.children;
|
|
202
|
+
var nestedCandidates = getCandidatesIteratively(content, true, options);
|
|
172
203
|
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
if (options.flatten) {
|
|
205
|
+
candidates.push.apply(candidates, nestedCandidates);
|
|
206
|
+
} else {
|
|
207
|
+
candidates.push({
|
|
208
|
+
scope: element,
|
|
209
|
+
candidates: nestedCandidates
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
// check candidate element
|
|
214
|
+
var validCandidate = matches.call(element, candidateSelector);
|
|
215
|
+
|
|
216
|
+
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
|
|
217
|
+
candidates.push(element);
|
|
218
|
+
} // iterate over shadow content if possible
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
var shadowRoot = element.shadowRoot || // check for an undisclosed shadow
|
|
222
|
+
typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
|
|
223
|
+
|
|
224
|
+
if (shadowRoot) {
|
|
225
|
+
// add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
|
|
226
|
+
// shadow exists, so look at light dom children as fallback BUT create a scope for any
|
|
227
|
+
// child candidates found because they're likely slotted elements (elements that are
|
|
228
|
+
// children of the web component element (which has the shadow), in the light dom, but
|
|
229
|
+
// slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
|
|
230
|
+
// _after_ we return from this recursive call
|
|
231
|
+
var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
|
|
232
|
+
|
|
233
|
+
if (options.flatten) {
|
|
234
|
+
candidates.push.apply(candidates, _nestedCandidates);
|
|
235
|
+
} else {
|
|
236
|
+
candidates.push({
|
|
237
|
+
scope: element,
|
|
238
|
+
candidates: _nestedCandidates
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
// there's not shadow so just dig into the element's (light dom) children
|
|
243
|
+
// __without__ giving the element special scope treatment
|
|
244
|
+
elementsToCheck.unshift.apply(elementsToCheck, element.children);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return candidates;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
var getTabindex = function getTabindex(node, isScope) {
|
|
253
|
+
if (node.tabIndex < 0) {
|
|
254
|
+
// in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
|
255
|
+
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
|
256
|
+
// yet they are still part of the regular tab order; in FF, they get a default
|
|
257
|
+
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
|
258
|
+
// order, consider their tab index to be 0.
|
|
259
|
+
// Also browsers do not return `tabIndex` correctly for contentEditable nodes;
|
|
260
|
+
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
261
|
+
//
|
|
262
|
+
// isScope is positive for custom element with shadow root or slot that by default
|
|
263
|
+
// have tabIndex -1, but need to be sorted by document order in order for their
|
|
264
|
+
// content to be inserted in the correct position
|
|
265
|
+
if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute('tabindex'), 10))) {
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
175
268
|
}
|
|
176
269
|
|
|
177
270
|
return node.tabIndex;
|
|
@@ -209,8 +302,26 @@
|
|
|
209
302
|
return true;
|
|
210
303
|
}
|
|
211
304
|
|
|
212
|
-
var radioScope = node.form || node
|
|
213
|
-
|
|
305
|
+
var radioScope = node.form || getRootNode(node);
|
|
306
|
+
|
|
307
|
+
var queryRadios = function queryRadios(name) {
|
|
308
|
+
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
var radioSet;
|
|
312
|
+
|
|
313
|
+
if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
|
|
314
|
+
radioSet = queryRadios(window.CSS.escape(node.name));
|
|
315
|
+
} else {
|
|
316
|
+
try {
|
|
317
|
+
radioSet = queryRadios(node.name);
|
|
318
|
+
} catch (err) {
|
|
319
|
+
// eslint-disable-next-line no-console
|
|
320
|
+
console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
214
325
|
var checked = getCheckedRadio(radioSet, node.form);
|
|
215
326
|
return !checked || checked === node;
|
|
216
327
|
};
|
|
@@ -223,7 +334,23 @@
|
|
|
223
334
|
return isRadio(node) && !isTabbableRadio(node);
|
|
224
335
|
};
|
|
225
336
|
|
|
226
|
-
var
|
|
337
|
+
var isZeroArea = function isZeroArea(node) {
|
|
338
|
+
var _node$getBoundingClie = node.getBoundingClientRect(),
|
|
339
|
+
width = _node$getBoundingClie.width,
|
|
340
|
+
height = _node$getBoundingClie.height;
|
|
341
|
+
|
|
342
|
+
return width === 0 && height === 0;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
var isHidden = function isHidden(node, _ref) {
|
|
346
|
+
var displayCheck = _ref.displayCheck,
|
|
347
|
+
getShadowRoot = _ref.getShadowRoot;
|
|
348
|
+
|
|
349
|
+
// NOTE: visibility will be `undefined` if node is detached from the document
|
|
350
|
+
// (see notes about this further down), which means we will consider it visible
|
|
351
|
+
// (this is legacy behavior from a very long way back)
|
|
352
|
+
// NOTE: we check this regardless of `displayCheck="none"` because this is a
|
|
353
|
+
// _visibility_ check, not a _display_ check
|
|
227
354
|
if (getComputedStyle(node).visibility === 'hidden') {
|
|
228
355
|
return true;
|
|
229
356
|
}
|
|
@@ -233,64 +360,234 @@
|
|
|
233
360
|
|
|
234
361
|
if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
|
|
235
362
|
return true;
|
|
236
|
-
}
|
|
363
|
+
} // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
|
|
364
|
+
// (but NOT _the_ document; see second 'If' comment below for more).
|
|
365
|
+
// If rootNode is shadow root, it'll have a host, which is the element to which the shadow
|
|
366
|
+
// is attached, and the one we need to check if it's in the document or not (because the
|
|
367
|
+
// shadow, and all nodes it contains, is never considered in the document since shadows
|
|
368
|
+
// behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
|
|
369
|
+
// is hidden, or is not in the document itself but is detached, it will affect the shadow's
|
|
370
|
+
// visibility, including all the nodes it contains). The host could be any normal node,
|
|
371
|
+
// or a custom element (i.e. web component). Either way, that's the one that is considered
|
|
372
|
+
// part of the document, not the shadow root, nor any of its children (i.e. the node being
|
|
373
|
+
// tested).
|
|
374
|
+
// If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
|
|
375
|
+
// document (per the docs) and while it's a Document-type object, that document does not
|
|
376
|
+
// appear to be the same as the node's `ownerDocument` for some reason, so it's safer
|
|
377
|
+
// to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
|
|
378
|
+
// using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
|
|
379
|
+
// node is actually detached.
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
var nodeRootHost = getRootNode(node).host;
|
|
383
|
+
var nodeIsAttached = (nodeRootHost === null || nodeRootHost === void 0 ? void 0 : nodeRootHost.ownerDocument.contains(nodeRootHost)) || node.ownerDocument.contains(node);
|
|
384
|
+
|
|
385
|
+
if (!displayCheck || displayCheck === 'full') {
|
|
386
|
+
if (typeof getShadowRoot === 'function') {
|
|
387
|
+
// figure out if we should consider the node to be in an undisclosed shadow and use the
|
|
388
|
+
// 'non-zero-area' fallback
|
|
389
|
+
var originalNode = node;
|
|
390
|
+
|
|
391
|
+
while (node) {
|
|
392
|
+
var parentElement = node.parentElement;
|
|
393
|
+
var rootNode = getRootNode(node);
|
|
394
|
+
|
|
395
|
+
if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
|
|
396
|
+
) {
|
|
397
|
+
// node has an undisclosed shadow which means we can only treat it as a black box, so we
|
|
398
|
+
// fall back to a non-zero-area test
|
|
399
|
+
return isZeroArea(node);
|
|
400
|
+
} else if (node.assignedSlot) {
|
|
401
|
+
// iterate up slot
|
|
402
|
+
node = node.assignedSlot;
|
|
403
|
+
} else if (!parentElement && rootNode !== node.ownerDocument) {
|
|
404
|
+
// cross shadow boundary
|
|
405
|
+
node = rootNode.host;
|
|
406
|
+
} else {
|
|
407
|
+
// iterate up normal dom
|
|
408
|
+
node = parentElement;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
237
411
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
412
|
+
node = originalNode;
|
|
413
|
+
} // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
|
|
414
|
+
// (i.e. it does not also presume that all nodes might have undisclosed shadows); or
|
|
415
|
+
// it might be a falsy value, which means shadow DOM support is disabled
|
|
416
|
+
// Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
|
|
417
|
+
// now we can just test to see if it would normally be visible or not, provided it's
|
|
418
|
+
// attached to the main document.
|
|
419
|
+
// NOTE: We must consider case where node is inside a shadow DOM and given directly to
|
|
420
|
+
// `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
if (nodeIsAttached) {
|
|
424
|
+
// this works wherever the node is: if there's at least one client rect, it's
|
|
425
|
+
// somehow displayed; it also covers the CSS 'display: contents' case where the
|
|
426
|
+
// node itself is hidden in place of its contents; and there's no need to search
|
|
427
|
+
// up the hierarchy either
|
|
428
|
+
return !node.getClientRects().length;
|
|
429
|
+
} // Else, the node isn't attached to the document, which means the `getClientRects()`
|
|
430
|
+
// API will __always__ return zero rects (this can happen, for example, if React
|
|
431
|
+
// is used to render nodes onto a detached tree, as confirmed in this thread:
|
|
432
|
+
// https://github.com/facebook/react/issues/9117#issuecomment-284228870)
|
|
433
|
+
//
|
|
434
|
+
// It also means that even window.getComputedStyle(node).display will return `undefined`
|
|
435
|
+
// because styles are only computed for nodes that are in the document.
|
|
436
|
+
//
|
|
437
|
+
// NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
|
|
438
|
+
// somehow. Though it was never stated officially, anyone who has ever used tabbable
|
|
439
|
+
// APIs on nodes in detached containers has actually implicitly used tabbable in what
|
|
440
|
+
// was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
|
|
441
|
+
// considering __everything__ to be visible because of the innability to determine styles.
|
|
442
|
+
|
|
443
|
+
} else if (displayCheck === 'non-zero-area') {
|
|
444
|
+
// NOTE: Even though this tests that the node's client rect is non-zero to determine
|
|
445
|
+
// whether it's displayed, and that a detached node will __always__ have a zero-area
|
|
446
|
+
// client rect, we don't special-case for whether the node is attached or not. In
|
|
447
|
+
// this mode, we do want to consider nodes that have a zero area to be hidden at all
|
|
448
|
+
// times, and that includes attached or not.
|
|
449
|
+
return isZeroArea(node);
|
|
450
|
+
} // visible, as far as we can tell, or per current `displayCheck` mode
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
return false;
|
|
454
|
+
}; // form fields (nested) inside a disabled fieldset are not focusable/tabbable
|
|
455
|
+
// unless they are in the _first_ <legend> element of the top-most disabled
|
|
456
|
+
// fieldset
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
|
|
460
|
+
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
|
|
461
|
+
var parentNode = node.parentElement; // check if `node` is contained in a disabled <fieldset>
|
|
462
|
+
|
|
463
|
+
while (parentNode) {
|
|
464
|
+
if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
|
|
465
|
+
// look for the first <legend> among the children of the disabled <fieldset>
|
|
466
|
+
for (var i = 0; i < parentNode.children.length; i++) {
|
|
467
|
+
var child = parentNode.children.item(i); // when the first <legend> (in document order) is found
|
|
468
|
+
|
|
469
|
+
if (child.tagName === 'LEGEND') {
|
|
470
|
+
// if its parent <fieldset> is not nested in another disabled <fieldset>,
|
|
471
|
+
// return whether `node` is a descendant of its first <legend>
|
|
472
|
+
return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
|
|
473
|
+
}
|
|
474
|
+
} // the disabled <fieldset> containing `node` has no <legend>
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
parentNode = parentNode.parentElement;
|
|
241
481
|
}
|
|
482
|
+
} // else, node's tabbable/focusable state should not be affected by a fieldset's
|
|
483
|
+
// enabled/disabled state
|
|
242
484
|
|
|
243
|
-
node = node.parentElement;
|
|
244
|
-
}
|
|
245
485
|
|
|
246
486
|
return false;
|
|
247
487
|
};
|
|
248
488
|
|
|
249
|
-
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(node) {
|
|
250
|
-
if (node.disabled || isHiddenInput(node) || isHidden(node) ||
|
|
251
|
-
|
|
252
|
-
isDetailsWithSummary(node)) {
|
|
489
|
+
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
|
|
490
|
+
if (node.disabled || isHiddenInput(node) || isHidden(node, options) || // For a details element with a summary, the summary element gets the focus
|
|
491
|
+
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
|
|
253
492
|
return false;
|
|
254
493
|
}
|
|
255
494
|
|
|
256
495
|
return true;
|
|
257
496
|
};
|
|
258
497
|
|
|
259
|
-
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(node) {
|
|
260
|
-
if (
|
|
498
|
+
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
|
|
499
|
+
if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
|
|
261
500
|
return false;
|
|
262
501
|
}
|
|
263
502
|
|
|
264
503
|
return true;
|
|
265
504
|
};
|
|
505
|
+
/**
|
|
506
|
+
* @param {Array.<Element|CandidatesScope>} candidates
|
|
507
|
+
* @returns Element[]
|
|
508
|
+
*/
|
|
266
509
|
|
|
267
|
-
|
|
268
|
-
|
|
510
|
+
|
|
511
|
+
var sortByOrder = function sortByOrder(candidates) {
|
|
269
512
|
var regularTabbables = [];
|
|
270
513
|
var orderedTabbables = [];
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var
|
|
514
|
+
candidates.forEach(function (item, i) {
|
|
515
|
+
var isScope = !!item.scope;
|
|
516
|
+
var element = isScope ? item.scope : item;
|
|
517
|
+
var candidateTabindex = getTabindex(element, isScope);
|
|
518
|
+
var elements = isScope ? sortByOrder(item.candidates) : element;
|
|
274
519
|
|
|
275
520
|
if (candidateTabindex === 0) {
|
|
276
|
-
regularTabbables.push(
|
|
521
|
+
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
|
|
277
522
|
} else {
|
|
278
523
|
orderedTabbables.push({
|
|
279
524
|
documentOrder: i,
|
|
280
525
|
tabIndex: candidateTabindex,
|
|
281
|
-
|
|
526
|
+
item: item,
|
|
527
|
+
isScope: isScope,
|
|
528
|
+
content: elements
|
|
282
529
|
});
|
|
283
530
|
}
|
|
284
531
|
});
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
532
|
+
return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
|
|
533
|
+
sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
|
|
534
|
+
return acc;
|
|
535
|
+
}, []).concat(regularTabbables);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
var tabbable = function tabbable(el, options) {
|
|
539
|
+
options = options || {};
|
|
540
|
+
var candidates;
|
|
541
|
+
|
|
542
|
+
if (options.getShadowRoot) {
|
|
543
|
+
candidates = getCandidatesIteratively([el], options.includeContainer, {
|
|
544
|
+
filter: isNodeMatchingSelectorTabbable.bind(null, options),
|
|
545
|
+
flatten: false,
|
|
546
|
+
getShadowRoot: options.getShadowRoot
|
|
547
|
+
});
|
|
548
|
+
} else {
|
|
549
|
+
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return sortByOrder(candidates);
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
var focusable = function focusable(el, options) {
|
|
556
|
+
options = options || {};
|
|
557
|
+
var candidates;
|
|
558
|
+
|
|
559
|
+
if (options.getShadowRoot) {
|
|
560
|
+
candidates = getCandidatesIteratively([el], options.includeContainer, {
|
|
561
|
+
filter: isNodeMatchingSelectorFocusable.bind(null, options),
|
|
562
|
+
flatten: true,
|
|
563
|
+
getShadowRoot: options.getShadowRoot
|
|
564
|
+
});
|
|
565
|
+
} else {
|
|
566
|
+
candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return candidates;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
var isTabbable = function isTabbable(node, options) {
|
|
573
|
+
options = options || {};
|
|
574
|
+
|
|
575
|
+
if (!node) {
|
|
576
|
+
throw new Error('No node provided');
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (matches.call(node, candidateSelector) === false) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
return isNodeMatchingSelectorTabbable(options, node);
|
|
289
584
|
};
|
|
290
585
|
|
|
291
586
|
var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
|
|
292
587
|
|
|
293
|
-
var isFocusable = function isFocusable(node) {
|
|
588
|
+
var isFocusable = function isFocusable(node, options) {
|
|
589
|
+
options = options || {};
|
|
590
|
+
|
|
294
591
|
if (!node) {
|
|
295
592
|
throw new Error('No node provided');
|
|
296
593
|
}
|
|
@@ -299,38 +596,22 @@
|
|
|
299
596
|
return false;
|
|
300
597
|
}
|
|
301
598
|
|
|
302
|
-
return isNodeMatchingSelectorFocusable(node);
|
|
599
|
+
return isNodeMatchingSelectorFocusable(options, node);
|
|
303
600
|
};
|
|
304
601
|
|
|
305
602
|
/*!
|
|
306
|
-
* focus-trap 6.
|
|
603
|
+
* focus-trap 6.9.2
|
|
307
604
|
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
|
|
308
605
|
*/
|
|
309
606
|
|
|
310
|
-
function _defineProperty$1(obj, key, value) {
|
|
311
|
-
if (key in obj) {
|
|
312
|
-
Object.defineProperty(obj, key, {
|
|
313
|
-
value: value,
|
|
314
|
-
enumerable: true,
|
|
315
|
-
configurable: true,
|
|
316
|
-
writable: true
|
|
317
|
-
});
|
|
318
|
-
} else {
|
|
319
|
-
obj[key] = value;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return obj;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
607
|
function ownKeys(object, enumerableOnly) {
|
|
326
608
|
var keys = Object.keys(object);
|
|
327
609
|
|
|
328
610
|
if (Object.getOwnPropertySymbols) {
|
|
329
611
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
330
|
-
|
|
612
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
331
613
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
332
|
-
});
|
|
333
|
-
keys.push.apply(keys, symbols);
|
|
614
|
+
})), keys.push.apply(keys, symbols);
|
|
334
615
|
}
|
|
335
616
|
|
|
336
617
|
return keys;
|
|
@@ -338,25 +619,31 @@
|
|
|
338
619
|
|
|
339
620
|
function _objectSpread2(target) {
|
|
340
621
|
for (var i = 1; i < arguments.length; i++) {
|
|
341
|
-
var source = arguments[i]
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
348
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
349
|
-
} else {
|
|
350
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
351
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
352
|
-
});
|
|
353
|
-
}
|
|
622
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
623
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
624
|
+
_defineProperty$1(target, key, source[key]);
|
|
625
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
626
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
627
|
+
});
|
|
354
628
|
}
|
|
355
629
|
|
|
356
630
|
return target;
|
|
357
631
|
}
|
|
358
632
|
|
|
359
|
-
|
|
633
|
+
function _defineProperty$1(obj, key, value) {
|
|
634
|
+
if (key in obj) {
|
|
635
|
+
Object.defineProperty(obj, key, {
|
|
636
|
+
value: value,
|
|
637
|
+
enumerable: true,
|
|
638
|
+
configurable: true,
|
|
639
|
+
writable: true
|
|
640
|
+
});
|
|
641
|
+
} else {
|
|
642
|
+
obj[key] = value;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return obj;
|
|
646
|
+
}
|
|
360
647
|
|
|
361
648
|
var activeFocusTraps = function () {
|
|
362
649
|
var trapQueue = [];
|
|
@@ -408,10 +695,54 @@
|
|
|
408
695
|
|
|
409
696
|
var delay = function delay(fn) {
|
|
410
697
|
return setTimeout(fn, 0);
|
|
698
|
+
}; // Array.find/findIndex() are not supported on IE; this replicates enough
|
|
699
|
+
// of Array.findIndex() for our needs
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
var findIndex = function findIndex(arr, fn) {
|
|
703
|
+
var idx = -1;
|
|
704
|
+
arr.every(function (value, i) {
|
|
705
|
+
if (fn(value)) {
|
|
706
|
+
idx = i;
|
|
707
|
+
return false; // break
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return true; // next
|
|
711
|
+
});
|
|
712
|
+
return idx;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* Get an option's value when it could be a plain value, or a handler that provides
|
|
716
|
+
* the value.
|
|
717
|
+
* @param {*} value Option's value to check.
|
|
718
|
+
* @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
|
|
719
|
+
* @returns {*} The `value`, or the handler's returned value.
|
|
720
|
+
*/
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
var valueOrHandler = function valueOrHandler(value) {
|
|
724
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
725
|
+
params[_key - 1] = arguments[_key];
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
return typeof value === 'function' ? value.apply(void 0, params) : value;
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
var getActualTarget = function getActualTarget(event) {
|
|
732
|
+
// NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
|
|
733
|
+
// shadow host. However, event.target.composedPath() will be an array of
|
|
734
|
+
// nodes "clicked" from inner-most (the actual element inside the shadow) to
|
|
735
|
+
// outer-most (the host HTML document). If we have access to composedPath(),
|
|
736
|
+
// then use its first element; otherwise, fall back to event.target (and
|
|
737
|
+
// this only works for an _open_ shadow DOM; otherwise,
|
|
738
|
+
// composedPath()[0] === event.target always).
|
|
739
|
+
return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
|
|
411
740
|
};
|
|
412
741
|
|
|
413
742
|
var createFocusTrap = function createFocusTrap(elements, userOptions) {
|
|
414
|
-
|
|
743
|
+
// SSR: a live trap shouldn't be created in this type of environment so this
|
|
744
|
+
// should be safe code to execute if the `document` option isn't specified
|
|
745
|
+
var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
|
|
415
746
|
|
|
416
747
|
var config = _objectSpread2({
|
|
417
748
|
returnFocusOnDeactivate: true,
|
|
@@ -420,51 +751,122 @@
|
|
|
420
751
|
}, userOptions);
|
|
421
752
|
|
|
422
753
|
var state = {
|
|
754
|
+
// containers given to createFocusTrap()
|
|
423
755
|
// @type {Array<HTMLElement>}
|
|
424
756
|
containers: [],
|
|
425
|
-
// list of objects identifying
|
|
426
|
-
// the trap
|
|
757
|
+
// list of objects identifying tabbable nodes in `containers` in the trap
|
|
427
758
|
// NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
|
|
428
759
|
// is active, but the trap should never get to a state where there isn't at least one group
|
|
429
760
|
// with at least one tabbable node in it (that would lead to an error condition that would
|
|
430
761
|
// result in an error being thrown)
|
|
431
|
-
// @type {Array<{
|
|
762
|
+
// @type {Array<{
|
|
763
|
+
// container: HTMLElement,
|
|
764
|
+
// tabbableNodes: Array<HTMLElement>, // empty if none
|
|
765
|
+
// focusableNodes: Array<HTMLElement>, // empty if none
|
|
766
|
+
// firstTabbableNode: HTMLElement|null,
|
|
767
|
+
// lastTabbableNode: HTMLElement|null,
|
|
768
|
+
// nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
|
|
769
|
+
// }>}
|
|
770
|
+
containerGroups: [],
|
|
771
|
+
// same order/length as `containers` list
|
|
772
|
+
// references to objects in `containerGroups`, but only those that actually have
|
|
773
|
+
// tabbable nodes in them
|
|
774
|
+
// NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
|
|
775
|
+
// the same length
|
|
432
776
|
tabbableGroups: [],
|
|
433
777
|
nodeFocusedBeforeActivation: null,
|
|
434
778
|
mostRecentlyFocusedNode: null,
|
|
435
779
|
active: false,
|
|
436
|
-
paused: false
|
|
780
|
+
paused: false,
|
|
781
|
+
// timer ID for when delayInitialFocus is true and initial focus in this trap
|
|
782
|
+
// has been delayed during activation
|
|
783
|
+
delayInitialFocusTimer: undefined
|
|
437
784
|
};
|
|
438
785
|
var trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later
|
|
439
786
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
787
|
+
/**
|
|
788
|
+
* Gets a configuration option value.
|
|
789
|
+
* @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
|
|
790
|
+
* value will be taken from this object. Otherwise, value will be taken from base configuration.
|
|
791
|
+
* @param {string} optionName Name of the option whose value is sought.
|
|
792
|
+
* @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
|
|
793
|
+
* IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
|
|
794
|
+
*/
|
|
795
|
+
|
|
796
|
+
var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
|
|
797
|
+
return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
|
|
798
|
+
};
|
|
799
|
+
/**
|
|
800
|
+
* Finds the index of the container that contains the element.
|
|
801
|
+
* @param {HTMLElement} element
|
|
802
|
+
* @returns {number} Index of the container in either `state.containers` or
|
|
803
|
+
* `state.containerGroups` (the order/length of these lists are the same); -1
|
|
804
|
+
* if the element isn't found.
|
|
805
|
+
*/
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
var findContainerIndex = function findContainerIndex(element) {
|
|
809
|
+
// NOTE: search `containerGroups` because it's possible a group contains no tabbable
|
|
810
|
+
// nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
|
|
811
|
+
// and we still need to find the element in there
|
|
812
|
+
return state.containerGroups.findIndex(function (_ref) {
|
|
813
|
+
var container = _ref.container,
|
|
814
|
+
tabbableNodes = _ref.tabbableNodes;
|
|
815
|
+
return container.contains(element) || // fall back to explicit tabbable search which will take into consideration any
|
|
816
|
+
// web components if the `tabbableOptions.getShadowRoot` option was used for
|
|
817
|
+
// the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
|
|
818
|
+
// look inside web components even if open)
|
|
819
|
+
tabbableNodes.find(function (node) {
|
|
820
|
+
return node === element;
|
|
821
|
+
});
|
|
443
822
|
});
|
|
444
823
|
};
|
|
824
|
+
/**
|
|
825
|
+
* Gets the node for the given option, which is expected to be an option that
|
|
826
|
+
* can be either a DOM node, a string that is a selector to get a node, `false`
|
|
827
|
+
* (if a node is explicitly NOT given), or a function that returns any of these
|
|
828
|
+
* values.
|
|
829
|
+
* @param {string} optionName
|
|
830
|
+
* @returns {undefined | false | HTMLElement | SVGElement} Returns
|
|
831
|
+
* `undefined` if the option is not specified; `false` if the option
|
|
832
|
+
* resolved to `false` (node explicitly not given); otherwise, the resolved
|
|
833
|
+
* DOM node.
|
|
834
|
+
* @throws {Error} If the option is set, not `false`, and is not, or does not
|
|
835
|
+
* resolve to a node.
|
|
836
|
+
*/
|
|
837
|
+
|
|
445
838
|
|
|
446
839
|
var getNodeForOption = function getNodeForOption(optionName) {
|
|
447
840
|
var optionValue = config[optionName];
|
|
448
841
|
|
|
449
|
-
if (
|
|
450
|
-
|
|
842
|
+
if (typeof optionValue === 'function') {
|
|
843
|
+
for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
844
|
+
params[_key2 - 1] = arguments[_key2];
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
optionValue = optionValue.apply(void 0, params);
|
|
451
848
|
}
|
|
452
849
|
|
|
453
|
-
|
|
850
|
+
if (optionValue === true) {
|
|
851
|
+
optionValue = undefined; // use default value
|
|
852
|
+
}
|
|
454
853
|
|
|
455
|
-
if (
|
|
456
|
-
|
|
854
|
+
if (!optionValue) {
|
|
855
|
+
if (optionValue === undefined || optionValue === false) {
|
|
856
|
+
return optionValue;
|
|
857
|
+
} // else, empty string (invalid), null (invalid), 0 (invalid)
|
|
457
858
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
859
|
+
|
|
860
|
+
throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
|
|
461
861
|
}
|
|
462
862
|
|
|
463
|
-
|
|
464
|
-
|
|
863
|
+
var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
|
|
864
|
+
|
|
865
|
+
if (typeof optionValue === 'string') {
|
|
866
|
+
node = doc.querySelector(optionValue); // resolve to node, or null if fails
|
|
465
867
|
|
|
466
868
|
if (!node) {
|
|
467
|
-
throw new Error("`".concat(optionName, "`
|
|
869
|
+
throw new Error("`".concat(optionName, "` as selector refers to no known node"));
|
|
468
870
|
}
|
|
469
871
|
}
|
|
470
872
|
|
|
@@ -472,16 +874,22 @@
|
|
|
472
874
|
};
|
|
473
875
|
|
|
474
876
|
var getInitialFocusNode = function getInitialFocusNode() {
|
|
475
|
-
var node;
|
|
877
|
+
var node = getNodeForOption('initialFocus'); // false explicitly indicates we want no initialFocus at all
|
|
476
878
|
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
879
|
+
if (node === false) {
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
if (node === undefined) {
|
|
884
|
+
// option not specified: use fallback options
|
|
885
|
+
if (findContainerIndex(doc.activeElement) >= 0) {
|
|
886
|
+
node = doc.activeElement;
|
|
887
|
+
} else {
|
|
888
|
+
var firstTabbableGroup = state.tabbableGroups[0];
|
|
889
|
+
var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode; // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
|
|
890
|
+
|
|
891
|
+
node = firstTabbableNode || getNodeForOption('fallbackFocus');
|
|
892
|
+
}
|
|
485
893
|
}
|
|
486
894
|
|
|
487
895
|
if (!node) {
|
|
@@ -492,28 +900,73 @@
|
|
|
492
900
|
};
|
|
493
901
|
|
|
494
902
|
var updateTabbableNodes = function updateTabbableNodes() {
|
|
495
|
-
state.
|
|
496
|
-
var tabbableNodes = tabbable(container);
|
|
903
|
+
state.containerGroups = state.containers.map(function (container) {
|
|
904
|
+
var tabbableNodes = tabbable(container, config.tabbableOptions); // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
|
|
905
|
+
// are a superset of tabbable nodes
|
|
906
|
+
|
|
907
|
+
var focusableNodes = focusable(container, config.tabbableOptions);
|
|
908
|
+
return {
|
|
909
|
+
container: container,
|
|
910
|
+
tabbableNodes: tabbableNodes,
|
|
911
|
+
focusableNodes: focusableNodes,
|
|
912
|
+
firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null,
|
|
913
|
+
lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null,
|
|
497
914
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
915
|
+
/**
|
|
916
|
+
* Finds the __tabbable__ node that follows the given node in the specified direction,
|
|
917
|
+
* in this container, if any.
|
|
918
|
+
* @param {HTMLElement} node
|
|
919
|
+
* @param {boolean} [forward] True if going in forward tab order; false if going
|
|
920
|
+
* in reverse.
|
|
921
|
+
* @returns {HTMLElement|undefined} The next tabbable node, if any.
|
|
922
|
+
*/
|
|
923
|
+
nextTabbableNode: function nextTabbableNode(node) {
|
|
924
|
+
var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
925
|
+
// NOTE: If tabindex is positive (in order to manipulate the tab order separate
|
|
926
|
+
// from the DOM order), this __will not work__ because the list of focusableNodes,
|
|
927
|
+
// while it contains tabbable nodes, does not sort its nodes in any order other
|
|
928
|
+
// than DOM order, because it can't: Where would you place focusable (but not
|
|
929
|
+
// tabbable) nodes in that order? They have no order, because they aren't tabbale...
|
|
930
|
+
// Support for positive tabindex is already broken and hard to manage (possibly
|
|
931
|
+
// not supportable, TBD), so this isn't going to make things worse than they
|
|
932
|
+
// already are, and at least makes things better for the majority of cases where
|
|
933
|
+
// tabindex is either 0/unset or negative.
|
|
934
|
+
// FYI, positive tabindex issue: https://github.com/focus-trap/focus-trap/issues/375
|
|
935
|
+
var nodeIdx = focusableNodes.findIndex(function (n) {
|
|
936
|
+
return n === node;
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
if (nodeIdx < 0) {
|
|
940
|
+
return undefined;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
if (forward) {
|
|
944
|
+
return focusableNodes.slice(nodeIdx + 1).find(function (n) {
|
|
945
|
+
return isTabbable(n, config.tabbableOptions);
|
|
946
|
+
});
|
|
947
|
+
}
|
|
504
948
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
949
|
+
return focusableNodes.slice(0, nodeIdx).reverse().find(function (n) {
|
|
950
|
+
return isTabbable(n, config.tabbableOptions);
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
});
|
|
955
|
+
state.tabbableGroups = state.containerGroups.filter(function (group) {
|
|
956
|
+
return group.tabbableNodes.length > 0;
|
|
957
|
+
}); // throw if no groups have tabbable nodes and we don't have a fallback focus node either
|
|
510
958
|
|
|
511
|
-
if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus')
|
|
959
|
+
if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
|
|
960
|
+
) {
|
|
512
961
|
throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
|
|
513
962
|
}
|
|
514
963
|
};
|
|
515
964
|
|
|
516
965
|
var tryFocus = function tryFocus(node) {
|
|
966
|
+
if (node === false) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
|
|
517
970
|
if (node === doc.activeElement) {
|
|
518
971
|
return;
|
|
519
972
|
}
|
|
@@ -534,19 +987,21 @@
|
|
|
534
987
|
};
|
|
535
988
|
|
|
536
989
|
var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
|
|
537
|
-
var node = getNodeForOption('setReturnFocus');
|
|
538
|
-
return node ? node : previousActiveElement;
|
|
990
|
+
var node = getNodeForOption('setReturnFocus', previousActiveElement);
|
|
991
|
+
return node ? node : node === false ? false : previousActiveElement;
|
|
539
992
|
}; // This needs to be done on mousedown and touchstart instead of click
|
|
540
993
|
// so that it precedes the focus event.
|
|
541
994
|
|
|
542
995
|
|
|
543
996
|
var checkPointerDown = function checkPointerDown(e) {
|
|
544
|
-
|
|
997
|
+
var target = getActualTarget(e);
|
|
998
|
+
|
|
999
|
+
if (findContainerIndex(target) >= 0) {
|
|
545
1000
|
// allow the click since it ocurred inside the trap
|
|
546
1001
|
return;
|
|
547
1002
|
}
|
|
548
1003
|
|
|
549
|
-
if (config.clickOutsideDeactivates) {
|
|
1004
|
+
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
|
|
550
1005
|
// immediately deactivate the trap
|
|
551
1006
|
trap.deactivate({
|
|
552
1007
|
// if, on deactivation, we should return focus to the node originally-focused
|
|
@@ -560,7 +1015,7 @@
|
|
|
560
1015
|
// that was clicked, whether it's focusable or not; by setting
|
|
561
1016
|
// `returnFocus: true`, we'll attempt to re-focus the node originally-focused
|
|
562
1017
|
// on activation (or the configured `setReturnFocus` node)
|
|
563
|
-
returnFocus: config.returnFocusOnDeactivate && !isFocusable(
|
|
1018
|
+
returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions)
|
|
564
1019
|
});
|
|
565
1020
|
return;
|
|
566
1021
|
} // This is needed for mobile devices.
|
|
@@ -568,7 +1023,7 @@
|
|
|
568
1023
|
// then on mobile they will be blocked anyways if `touchstart` is blocked.)
|
|
569
1024
|
|
|
570
1025
|
|
|
571
|
-
if (
|
|
1026
|
+
if (valueOrHandler(config.allowOutsideClick, e)) {
|
|
572
1027
|
// allow the click outside the trap to take place
|
|
573
1028
|
return;
|
|
574
1029
|
} // otherwise, prevent the click
|
|
@@ -579,11 +1034,12 @@
|
|
|
579
1034
|
|
|
580
1035
|
|
|
581
1036
|
var checkFocusIn = function checkFocusIn(e) {
|
|
582
|
-
var
|
|
1037
|
+
var target = getActualTarget(e);
|
|
1038
|
+
var targetContained = findContainerIndex(target) >= 0; // In Firefox when you Tab out of an iframe the Document is briefly focused.
|
|
583
1039
|
|
|
584
|
-
if (targetContained ||
|
|
1040
|
+
if (targetContained || target instanceof Document) {
|
|
585
1041
|
if (targetContained) {
|
|
586
|
-
state.mostRecentlyFocusedNode =
|
|
1042
|
+
state.mostRecentlyFocusedNode = target;
|
|
587
1043
|
}
|
|
588
1044
|
} else {
|
|
589
1045
|
// escaped! pull it back in to where it just left
|
|
@@ -597,28 +1053,75 @@
|
|
|
597
1053
|
|
|
598
1054
|
|
|
599
1055
|
var checkTab = function checkTab(e) {
|
|
1056
|
+
var target = getActualTarget(e);
|
|
600
1057
|
updateTabbableNodes();
|
|
601
1058
|
var destinationNode = null;
|
|
602
1059
|
|
|
603
1060
|
if (state.tabbableGroups.length > 0) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
1061
|
+
// make sure the target is actually contained in a group
|
|
1062
|
+
// NOTE: the target may also be the container itself if it's focusable
|
|
1063
|
+
// with tabIndex='-1' and was given initial focus
|
|
1064
|
+
var containerIndex = findContainerIndex(target);
|
|
1065
|
+
var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
|
|
1066
|
+
|
|
1067
|
+
if (containerIndex < 0) {
|
|
1068
|
+
// target not found in any group: quite possible focus has escaped the trap,
|
|
1069
|
+
// so bring it back in to...
|
|
1070
|
+
if (e.shiftKey) {
|
|
1071
|
+
// ...the last node in the last group
|
|
1072
|
+
destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
|
|
1073
|
+
} else {
|
|
1074
|
+
// ...the first node in the first group
|
|
1075
|
+
destinationNode = state.tabbableGroups[0].firstTabbableNode;
|
|
1076
|
+
}
|
|
1077
|
+
} else if (e.shiftKey) {
|
|
1078
|
+
// REVERSE
|
|
1079
|
+
// is the target the first tabbable node in a group?
|
|
1080
|
+
var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref2) {
|
|
1081
|
+
var firstTabbableNode = _ref2.firstTabbableNode;
|
|
1082
|
+
return target === firstTabbableNode;
|
|
608
1083
|
});
|
|
609
1084
|
|
|
1085
|
+
if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
|
|
1086
|
+
// an exception case where the target is either the container itself, or
|
|
1087
|
+
// a non-tabbable node that was given focus (i.e. tabindex is negative
|
|
1088
|
+
// and user clicked on it or node was programmatically given focus)
|
|
1089
|
+
// and is not followed by any other tabbable node, in which
|
|
1090
|
+
// case, we should handle shift+tab as if focus were on the container's
|
|
1091
|
+
// first tabbable node, and go to the last tabbable node of the LAST group
|
|
1092
|
+
startOfGroupIndex = containerIndex;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
610
1095
|
if (startOfGroupIndex >= 0) {
|
|
1096
|
+
// YES: then shift+tab should go to the last tabbable node in the
|
|
1097
|
+
// previous group (and wrap around to the last tabbable node of
|
|
1098
|
+
// the LAST group if it's the first tabbable node of the FIRST group)
|
|
611
1099
|
var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
|
|
612
1100
|
var destinationGroup = state.tabbableGroups[destinationGroupIndex];
|
|
613
1101
|
destinationNode = destinationGroup.lastTabbableNode;
|
|
614
1102
|
}
|
|
615
1103
|
} else {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
1104
|
+
// FORWARD
|
|
1105
|
+
// is the target the last tabbable node in a group?
|
|
1106
|
+
var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
|
|
1107
|
+
var lastTabbableNode = _ref3.lastTabbableNode;
|
|
1108
|
+
return target === lastTabbableNode;
|
|
619
1109
|
});
|
|
620
1110
|
|
|
1111
|
+
if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
|
|
1112
|
+
// an exception case where the target is the container itself, or
|
|
1113
|
+
// a non-tabbable node that was given focus (i.e. tabindex is negative
|
|
1114
|
+
// and user clicked on it or node was programmatically given focus)
|
|
1115
|
+
// and is not followed by any other tabbable node, in which
|
|
1116
|
+
// case, we should handle tab as if focus were on the container's
|
|
1117
|
+
// last tabbable node, and go to the first tabbable node of the FIRST group
|
|
1118
|
+
lastOfGroupIndex = containerIndex;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
621
1121
|
if (lastOfGroupIndex >= 0) {
|
|
1122
|
+
// YES: then tab should go to the first tabbable node in the next
|
|
1123
|
+
// group (and wrap around to the first tabbable node of the FIRST
|
|
1124
|
+
// group if it's the last tabbable node of the LAST group)
|
|
622
1125
|
var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
|
|
623
1126
|
|
|
624
1127
|
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
|
|
@@ -626,17 +1129,19 @@
|
|
|
626
1129
|
}
|
|
627
1130
|
}
|
|
628
1131
|
} else {
|
|
1132
|
+
// NOTE: the fallbackFocus option does not support returning false to opt-out
|
|
629
1133
|
destinationNode = getNodeForOption('fallbackFocus');
|
|
630
1134
|
}
|
|
631
1135
|
|
|
632
1136
|
if (destinationNode) {
|
|
633
1137
|
e.preventDefault();
|
|
634
1138
|
tryFocus(destinationNode);
|
|
635
|
-
}
|
|
1139
|
+
} // else, let the browser take care of [shift+]tab and move the focus
|
|
1140
|
+
|
|
636
1141
|
};
|
|
637
1142
|
|
|
638
1143
|
var checkKey = function checkKey(e) {
|
|
639
|
-
if (config.escapeDeactivates !== false
|
|
1144
|
+
if (isEscapeEvent(e) && valueOrHandler(config.escapeDeactivates, e) !== false) {
|
|
640
1145
|
e.preventDefault();
|
|
641
1146
|
trap.deactivate();
|
|
642
1147
|
return;
|
|
@@ -649,15 +1154,17 @@
|
|
|
649
1154
|
};
|
|
650
1155
|
|
|
651
1156
|
var checkClick = function checkClick(e) {
|
|
652
|
-
|
|
1157
|
+
var target = getActualTarget(e);
|
|
1158
|
+
|
|
1159
|
+
if (findContainerIndex(target) >= 0) {
|
|
653
1160
|
return;
|
|
654
1161
|
}
|
|
655
1162
|
|
|
656
|
-
if (
|
|
1163
|
+
if (valueOrHandler(config.clickOutsideDeactivates, e)) {
|
|
657
1164
|
return;
|
|
658
1165
|
}
|
|
659
1166
|
|
|
660
|
-
if (
|
|
1167
|
+
if (valueOrHandler(config.allowOutsideClick, e)) {
|
|
661
1168
|
return;
|
|
662
1169
|
}
|
|
663
1170
|
|
|
@@ -677,7 +1184,7 @@
|
|
|
677
1184
|
activeFocusTraps.activateTrap(trap); // Delay ensures that the focused element doesn't capture the event
|
|
678
1185
|
// that caused the focus trap activation.
|
|
679
1186
|
|
|
680
|
-
|
|
1187
|
+
state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
|
|
681
1188
|
tryFocus(getInitialFocusNode());
|
|
682
1189
|
}) : tryFocus(getInitialFocusNode());
|
|
683
1190
|
doc.addEventListener('focusin', checkFocusIn, true);
|
|
@@ -717,22 +1224,53 @@
|
|
|
717
1224
|
|
|
718
1225
|
|
|
719
1226
|
trap = {
|
|
1227
|
+
get active() {
|
|
1228
|
+
return state.active;
|
|
1229
|
+
},
|
|
1230
|
+
|
|
1231
|
+
get paused() {
|
|
1232
|
+
return state.paused;
|
|
1233
|
+
},
|
|
1234
|
+
|
|
720
1235
|
activate: function activate(activateOptions) {
|
|
721
1236
|
if (state.active) {
|
|
722
1237
|
return this;
|
|
723
1238
|
}
|
|
724
1239
|
|
|
725
|
-
|
|
1240
|
+
var onActivate = getOption(activateOptions, 'onActivate');
|
|
1241
|
+
var onPostActivate = getOption(activateOptions, 'onPostActivate');
|
|
1242
|
+
var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
|
|
1243
|
+
|
|
1244
|
+
if (!checkCanFocusTrap) {
|
|
1245
|
+
updateTabbableNodes();
|
|
1246
|
+
}
|
|
1247
|
+
|
|
726
1248
|
state.active = true;
|
|
727
1249
|
state.paused = false;
|
|
728
1250
|
state.nodeFocusedBeforeActivation = doc.activeElement;
|
|
729
|
-
var onActivate = activateOptions && activateOptions.onActivate ? activateOptions.onActivate : config.onActivate;
|
|
730
1251
|
|
|
731
1252
|
if (onActivate) {
|
|
732
1253
|
onActivate();
|
|
733
1254
|
}
|
|
734
1255
|
|
|
735
|
-
|
|
1256
|
+
var finishActivation = function finishActivation() {
|
|
1257
|
+
if (checkCanFocusTrap) {
|
|
1258
|
+
updateTabbableNodes();
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
addListeners();
|
|
1262
|
+
|
|
1263
|
+
if (onPostActivate) {
|
|
1264
|
+
onPostActivate();
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
if (checkCanFocusTrap) {
|
|
1269
|
+
checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
|
|
1270
|
+
return this;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
finishActivation();
|
|
736
1274
|
return this;
|
|
737
1275
|
},
|
|
738
1276
|
deactivate: function deactivate(deactivateOptions) {
|
|
@@ -740,25 +1278,46 @@
|
|
|
740
1278
|
return this;
|
|
741
1279
|
}
|
|
742
1280
|
|
|
743
|
-
|
|
1281
|
+
var options = _objectSpread2({
|
|
1282
|
+
onDeactivate: config.onDeactivate,
|
|
1283
|
+
onPostDeactivate: config.onPostDeactivate,
|
|
1284
|
+
checkCanReturnFocus: config.checkCanReturnFocus
|
|
1285
|
+
}, deactivateOptions);
|
|
1286
|
+
|
|
1287
|
+
clearTimeout(state.delayInitialFocusTimer); // noop if undefined
|
|
1288
|
+
|
|
1289
|
+
state.delayInitialFocusTimer = undefined;
|
|
744
1290
|
removeListeners();
|
|
745
1291
|
state.active = false;
|
|
746
1292
|
state.paused = false;
|
|
747
1293
|
activeFocusTraps.deactivateTrap(trap);
|
|
748
|
-
var onDeactivate =
|
|
1294
|
+
var onDeactivate = getOption(options, 'onDeactivate');
|
|
1295
|
+
var onPostDeactivate = getOption(options, 'onPostDeactivate');
|
|
1296
|
+
var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
|
|
1297
|
+
var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
|
|
749
1298
|
|
|
750
1299
|
if (onDeactivate) {
|
|
751
1300
|
onDeactivate();
|
|
752
1301
|
}
|
|
753
1302
|
|
|
754
|
-
var
|
|
755
|
-
|
|
756
|
-
if (returnFocus) {
|
|
1303
|
+
var finishDeactivation = function finishDeactivation() {
|
|
757
1304
|
delay(function () {
|
|
758
|
-
|
|
1305
|
+
if (returnFocus) {
|
|
1306
|
+
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
if (onPostDeactivate) {
|
|
1310
|
+
onPostDeactivate();
|
|
1311
|
+
}
|
|
759
1312
|
});
|
|
1313
|
+
};
|
|
1314
|
+
|
|
1315
|
+
if (returnFocus && checkCanReturnFocus) {
|
|
1316
|
+
checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
|
|
1317
|
+
return this;
|
|
760
1318
|
}
|
|
761
1319
|
|
|
1320
|
+
finishDeactivation();
|
|
762
1321
|
return this;
|
|
763
1322
|
},
|
|
764
1323
|
pause: function pause() {
|
|
@@ -6837,6 +7396,7 @@
|
|
|
6837
7396
|
const content = (React__namespace.createElement(FocusTrap, Object.assign({ active: focusTrapActive, focusTrapOptions: {
|
|
6838
7397
|
returnFocusOnDeactivate: true,
|
|
6839
7398
|
clickOutsideDeactivates: true,
|
|
7399
|
+
tabbableOptions: { displayCheck: 'none' },
|
|
6840
7400
|
fallbackFocus: () => {
|
|
6841
7401
|
// If the popover's trigger is focused but scrolled out of view,
|
|
6842
7402
|
// FocusTrap will throw an error when the Enter button is used on the trigger.
|