This commit is contained in:
139
node_modules/react-modal/lib/helpers/ariaAppHider.js
generated
vendored
Normal file
139
node_modules/react-modal/lib/helpers/ariaAppHider.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resetState = resetState;
|
||||
exports.log = log;
|
||||
exports.assertNodeList = assertNodeList;
|
||||
exports.setElement = setElement;
|
||||
exports.validateElement = validateElement;
|
||||
exports.hide = hide;
|
||||
exports.show = show;
|
||||
exports.documentNotReadyOrSSRTesting = documentNotReadyOrSSRTesting;
|
||||
|
||||
var _warning = require("warning");
|
||||
|
||||
var _warning2 = _interopRequireDefault(_warning);
|
||||
|
||||
var _safeHTMLElement = require("./safeHTMLElement");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var globalElement = null;
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* istanbul ignore next */
|
||||
function resetState() {
|
||||
if (globalElement) {
|
||||
if (globalElement.removeAttribute) {
|
||||
globalElement.removeAttribute("aria-hidden");
|
||||
} else if (globalElement.length != null) {
|
||||
globalElement.forEach(function (element) {
|
||||
return element.removeAttribute("aria-hidden");
|
||||
});
|
||||
} else {
|
||||
document.querySelectorAll(globalElement).forEach(function (element) {
|
||||
return element.removeAttribute("aria-hidden");
|
||||
});
|
||||
}
|
||||
}
|
||||
globalElement = null;
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function log() {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
var check = globalElement || {};
|
||||
console.log("ariaAppHider ----------");
|
||||
console.log(check.nodeName, check.className, check.id);
|
||||
console.log("end ariaAppHider ----------");
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
function assertNodeList(nodeList, selector) {
|
||||
if (!nodeList || !nodeList.length) {
|
||||
throw new Error("react-modal: No elements were found for selector " + selector + ".");
|
||||
}
|
||||
}
|
||||
|
||||
function setElement(element) {
|
||||
var useElement = element;
|
||||
if (typeof useElement === "string" && _safeHTMLElement.canUseDOM) {
|
||||
var el = document.querySelectorAll(useElement);
|
||||
assertNodeList(el, useElement);
|
||||
useElement = el;
|
||||
}
|
||||
globalElement = useElement || globalElement;
|
||||
return globalElement;
|
||||
}
|
||||
|
||||
function validateElement(appElement) {
|
||||
var el = appElement || globalElement;
|
||||
if (el) {
|
||||
return Array.isArray(el) || el instanceof HTMLCollection || el instanceof NodeList ? el : [el];
|
||||
} else {
|
||||
(0, _warning2.default)(false, ["react-modal: App element is not defined.", "Please use `Modal.setAppElement(el)` or set `appElement={el}`.", "This is needed so screen readers don't see main content", "when modal is opened. It is not recommended, but you can opt-out", "by setting `ariaHideApp={false}`."].join(" "));
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function hide(appElement) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = validateElement(appElement)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var el = _step.value;
|
||||
|
||||
el.setAttribute("aria-hidden", "true");
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function show(appElement) {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = validateElement(appElement)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var el = _step2.value;
|
||||
|
||||
el.removeAttribute("aria-hidden");
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function documentNotReadyOrSSRTesting() {
|
||||
globalElement = null;
|
||||
}
|
||||
93
node_modules/react-modal/lib/helpers/bodyTrap.js
generated
vendored
Normal file
93
node_modules/react-modal/lib/helpers/bodyTrap.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resetState = resetState;
|
||||
exports.log = log;
|
||||
|
||||
var _portalOpenInstances = require("./portalOpenInstances");
|
||||
|
||||
var _portalOpenInstances2 = _interopRequireDefault(_portalOpenInstances);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Body focus trap see Issue #742
|
||||
|
||||
var before = void 0,
|
||||
after = void 0,
|
||||
instances = [];
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* istanbul ignore next */
|
||||
function resetState() {
|
||||
var _arr = [before, after];
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var item = _arr[_i];
|
||||
if (!item) continue;
|
||||
item.parentNode && item.parentNode.removeChild(item);
|
||||
}
|
||||
before = after = null;
|
||||
instances = [];
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function log() {
|
||||
console.log("bodyTrap ----------");
|
||||
console.log(instances.length);
|
||||
var _arr2 = [before, after];
|
||||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
||||
var item = _arr2[_i2];
|
||||
var check = item || {};
|
||||
console.log(check.nodeName, check.className, check.id);
|
||||
}
|
||||
console.log("edn bodyTrap ----------");
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
function focusContent() {
|
||||
if (instances.length === 0) {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("React-Modal: Open instances > 0 expected");
|
||||
}
|
||||
return;
|
||||
}
|
||||
instances[instances.length - 1].focusContent();
|
||||
}
|
||||
|
||||
function bodyTrap(eventType, openInstances) {
|
||||
if (!before && !after) {
|
||||
before = document.createElement("div");
|
||||
before.setAttribute("data-react-modal-body-trap", "");
|
||||
before.style.position = "absolute";
|
||||
before.style.opacity = "0";
|
||||
before.setAttribute("tabindex", "0");
|
||||
before.addEventListener("focus", focusContent);
|
||||
after = before.cloneNode();
|
||||
after.addEventListener("focus", focusContent);
|
||||
}
|
||||
|
||||
instances = openInstances;
|
||||
|
||||
if (instances.length > 0) {
|
||||
// Add focus trap
|
||||
if (document.body.firstChild !== before) {
|
||||
document.body.insertBefore(before, document.body.firstChild);
|
||||
}
|
||||
if (document.body.lastChild !== after) {
|
||||
document.body.appendChild(after);
|
||||
}
|
||||
} else {
|
||||
// Remove focus trap
|
||||
if (before.parentElement) {
|
||||
before.parentElement.removeChild(before);
|
||||
}
|
||||
if (after.parentElement) {
|
||||
after.parentElement.removeChild(after);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_portalOpenInstances2.default.subscribe(bodyTrap);
|
||||
130
node_modules/react-modal/lib/helpers/classList.js
generated
vendored
Normal file
130
node_modules/react-modal/lib/helpers/classList.js
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resetState = resetState;
|
||||
exports.log = log;
|
||||
var htmlClassList = {};
|
||||
var docBodyClassList = {};
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* istanbul ignore next */
|
||||
function removeClass(at, cls) {
|
||||
at.classList.remove(cls);
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function resetState() {
|
||||
var htmlElement = document.getElementsByTagName("html")[0];
|
||||
for (var cls in htmlClassList) {
|
||||
removeClass(htmlElement, htmlClassList[cls]);
|
||||
}
|
||||
|
||||
var body = document.body;
|
||||
for (var _cls in docBodyClassList) {
|
||||
removeClass(body, docBodyClassList[_cls]);
|
||||
}
|
||||
|
||||
htmlClassList = {};
|
||||
docBodyClassList = {};
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function log() {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
var classes = document.getElementsByTagName("html")[0].className;
|
||||
var buffer = "Show tracked classes:\n\n";
|
||||
|
||||
buffer += "<html /> (" + classes + "):\n ";
|
||||
for (var x in htmlClassList) {
|
||||
buffer += " " + x + " " + htmlClassList[x] + "\n ";
|
||||
}
|
||||
|
||||
classes = document.body.className;
|
||||
|
||||
buffer += "\n\ndoc.body (" + classes + "):\n ";
|
||||
for (var _x in docBodyClassList) {
|
||||
buffer += " " + _x + " " + docBodyClassList[_x] + "\n ";
|
||||
}
|
||||
|
||||
buffer += "\n";
|
||||
|
||||
console.log(buffer);
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
/**
|
||||
* Track the number of reference of a class.
|
||||
* @param {object} poll The poll to receive the reference.
|
||||
* @param {string} className The class name.
|
||||
* @return {string}
|
||||
*/
|
||||
var incrementReference = function incrementReference(poll, className) {
|
||||
if (!poll[className]) {
|
||||
poll[className] = 0;
|
||||
}
|
||||
poll[className] += 1;
|
||||
return className;
|
||||
};
|
||||
|
||||
/**
|
||||
* Drop the reference of a class.
|
||||
* @param {object} poll The poll to receive the reference.
|
||||
* @param {string} className The class name.
|
||||
* @return {string}
|
||||
*/
|
||||
var decrementReference = function decrementReference(poll, className) {
|
||||
if (poll[className]) {
|
||||
poll[className] -= 1;
|
||||
}
|
||||
return className;
|
||||
};
|
||||
|
||||
/**
|
||||
* Track a class and add to the given class list.
|
||||
* @param {Object} classListRef A class list of an element.
|
||||
* @param {Object} poll The poll to be used.
|
||||
* @param {Array} classes The list of classes to be tracked.
|
||||
*/
|
||||
var trackClass = function trackClass(classListRef, poll, classes) {
|
||||
classes.forEach(function (className) {
|
||||
incrementReference(poll, className);
|
||||
classListRef.add(className);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Untrack a class and remove from the given class list if the reference
|
||||
* reaches 0.
|
||||
* @param {Object} classListRef A class list of an element.
|
||||
* @param {Object} poll The poll to be used.
|
||||
* @param {Array} classes The list of classes to be untracked.
|
||||
*/
|
||||
var untrackClass = function untrackClass(classListRef, poll, classes) {
|
||||
classes.forEach(function (className) {
|
||||
decrementReference(poll, className);
|
||||
poll[className] === 0 && classListRef.remove(className);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Public inferface to add classes to the document.body.
|
||||
* @param {string} bodyClass The class string to be added.
|
||||
* It may contain more then one class
|
||||
* with ' ' as separator.
|
||||
*/
|
||||
var add = exports.add = function add(element, classString) {
|
||||
return trackClass(element.classList, element.nodeName.toLowerCase() == "html" ? htmlClassList : docBodyClassList, classString.split(" "));
|
||||
};
|
||||
|
||||
/**
|
||||
* Public inferface to remove classes from the document.body.
|
||||
* @param {string} bodyClass The class string to be added.
|
||||
* It may contain more then one class
|
||||
* with ' ' as separator.
|
||||
*/
|
||||
var remove = exports.remove = function remove(element, classString) {
|
||||
return untrackClass(element.classList, element.nodeName.toLowerCase() == "html" ? htmlClassList : docBodyClassList, classString.split(" "));
|
||||
};
|
||||
117
node_modules/react-modal/lib/helpers/focusManager.js
generated
vendored
Normal file
117
node_modules/react-modal/lib/helpers/focusManager.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.resetState = resetState;
|
||||
exports.log = log;
|
||||
exports.handleBlur = handleBlur;
|
||||
exports.handleFocus = handleFocus;
|
||||
exports.markForFocusLater = markForFocusLater;
|
||||
exports.returnFocus = returnFocus;
|
||||
exports.popWithoutFocus = popWithoutFocus;
|
||||
exports.setupScopedFocus = setupScopedFocus;
|
||||
exports.teardownScopedFocus = teardownScopedFocus;
|
||||
|
||||
var _tabbable = require("../helpers/tabbable");
|
||||
|
||||
var _tabbable2 = _interopRequireDefault(_tabbable);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var focusLaterElements = [];
|
||||
var modalElement = null;
|
||||
var needToFocus = false;
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* istanbul ignore next */
|
||||
function resetState() {
|
||||
focusLaterElements = [];
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function log() {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
console.log("focusManager ----------");
|
||||
focusLaterElements.forEach(function (f) {
|
||||
var check = f || {};
|
||||
console.log(check.nodeName, check.className, check.id);
|
||||
});
|
||||
console.log("end focusManager ----------");
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
function handleBlur() {
|
||||
needToFocus = true;
|
||||
}
|
||||
|
||||
function handleFocus() {
|
||||
if (needToFocus) {
|
||||
needToFocus = false;
|
||||
if (!modalElement) {
|
||||
return;
|
||||
}
|
||||
// need to see how jQuery shims document.on('focusin') so we don't need the
|
||||
// setTimeout, firefox doesn't support focusin, if it did, we could focus
|
||||
// the element outside of a setTimeout. Side-effect of this implementation
|
||||
// is that the document.body gets focus, and then we focus our element right
|
||||
// after, seems fine.
|
||||
setTimeout(function () {
|
||||
if (modalElement.contains(document.activeElement)) {
|
||||
return;
|
||||
}
|
||||
var el = (0, _tabbable2.default)(modalElement)[0] || modalElement;
|
||||
el.focus();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function markForFocusLater() {
|
||||
focusLaterElements.push(document.activeElement);
|
||||
}
|
||||
|
||||
/* eslint-disable no-console */
|
||||
function returnFocus() {
|
||||
var preventScroll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
||||
|
||||
var toFocus = null;
|
||||
try {
|
||||
if (focusLaterElements.length !== 0) {
|
||||
toFocus = focusLaterElements.pop();
|
||||
toFocus.focus({ preventScroll: preventScroll });
|
||||
}
|
||||
return;
|
||||
} catch (e) {
|
||||
console.warn(["You tried to return focus to", toFocus, "but it is not in the DOM anymore"].join(" "));
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
function popWithoutFocus() {
|
||||
focusLaterElements.length > 0 && focusLaterElements.pop();
|
||||
}
|
||||
|
||||
function setupScopedFocus(element) {
|
||||
modalElement = element;
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener("blur", handleBlur, false);
|
||||
document.addEventListener("focus", handleFocus, true);
|
||||
} else {
|
||||
window.attachEvent("onBlur", handleBlur);
|
||||
document.attachEvent("onFocus", handleFocus);
|
||||
}
|
||||
}
|
||||
|
||||
function teardownScopedFocus() {
|
||||
modalElement = null;
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.removeEventListener("blur", handleBlur);
|
||||
document.removeEventListener("focus", handleFocus);
|
||||
} else {
|
||||
window.detachEvent("onBlur", handleBlur);
|
||||
document.detachEvent("onFocus", handleFocus);
|
||||
}
|
||||
}
|
||||
78
node_modules/react-modal/lib/helpers/portalOpenInstances.js
generated
vendored
Normal file
78
node_modules/react-modal/lib/helpers/portalOpenInstances.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.log = log;
|
||||
exports.resetState = resetState;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
// Tracks portals that are open and emits events to subscribers
|
||||
|
||||
var PortalOpenInstances = function PortalOpenInstances() {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, PortalOpenInstances);
|
||||
|
||||
this.register = function (openInstance) {
|
||||
if (_this.openInstances.indexOf(openInstance) !== -1) {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("React-Modal: Cannot register modal instance that's already open");
|
||||
}
|
||||
return;
|
||||
}
|
||||
_this.openInstances.push(openInstance);
|
||||
_this.emit("register");
|
||||
};
|
||||
|
||||
this.deregister = function (openInstance) {
|
||||
var index = _this.openInstances.indexOf(openInstance);
|
||||
if (index === -1) {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("React-Modal: Unable to deregister " + openInstance + " as " + "it was never registered");
|
||||
}
|
||||
return;
|
||||
}
|
||||
_this.openInstances.splice(index, 1);
|
||||
_this.emit("deregister");
|
||||
};
|
||||
|
||||
this.subscribe = function (callback) {
|
||||
_this.subscribers.push(callback);
|
||||
};
|
||||
|
||||
this.emit = function (eventType) {
|
||||
_this.subscribers.forEach(function (subscriber) {
|
||||
return subscriber(eventType,
|
||||
// shallow copy to avoid accidental mutation
|
||||
_this.openInstances.slice());
|
||||
});
|
||||
};
|
||||
|
||||
this.openInstances = [];
|
||||
this.subscribers = [];
|
||||
};
|
||||
|
||||
var portalOpenInstances = new PortalOpenInstances();
|
||||
|
||||
/* eslint-disable no-console */
|
||||
/* istanbul ignore next */
|
||||
function log() {
|
||||
console.log("portalOpenInstances ----------");
|
||||
console.log(portalOpenInstances.openInstances.length);
|
||||
portalOpenInstances.openInstances.forEach(function (p) {
|
||||
return console.log(p);
|
||||
});
|
||||
console.log("end portalOpenInstances ----------");
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
function resetState() {
|
||||
portalOpenInstances = new PortalOpenInstances();
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
|
||||
exports.default = portalOpenInstances;
|
||||
24
node_modules/react-modal/lib/helpers/safeHTMLElement.js
generated
vendored
Normal file
24
node_modules/react-modal/lib/helpers/safeHTMLElement.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.canUseDOM = exports.SafeNodeList = exports.SafeHTMLCollection = undefined;
|
||||
|
||||
var _exenv = require("exenv");
|
||||
|
||||
var _exenv2 = _interopRequireDefault(_exenv);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var EE = _exenv2.default;
|
||||
|
||||
var SafeHTMLElement = EE.canUseDOM ? window.HTMLElement : {};
|
||||
|
||||
var SafeHTMLCollection = exports.SafeHTMLCollection = EE.canUseDOM ? window.HTMLCollection : {};
|
||||
|
||||
var SafeNodeList = exports.SafeNodeList = EE.canUseDOM ? window.NodeList : {};
|
||||
|
||||
var canUseDOM = exports.canUseDOM = EE.canUseDOM;
|
||||
|
||||
exports.default = SafeHTMLElement;
|
||||
96
node_modules/react-modal/lib/helpers/scopeTab.js
generated
vendored
Normal file
96
node_modules/react-modal/lib/helpers/scopeTab.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = scopeTab;
|
||||
|
||||
var _tabbable = require("./tabbable");
|
||||
|
||||
var _tabbable2 = _interopRequireDefault(_tabbable);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function getActiveElement() {
|
||||
var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
|
||||
|
||||
return el.activeElement.shadowRoot ? getActiveElement(el.activeElement.shadowRoot) : el.activeElement;
|
||||
}
|
||||
|
||||
function scopeTab(node, event) {
|
||||
var tabbable = (0, _tabbable2.default)(node);
|
||||
|
||||
if (!tabbable.length) {
|
||||
// Do nothing, since there are no elements that can receive focus.
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
var target = void 0;
|
||||
|
||||
var shiftKey = event.shiftKey;
|
||||
var head = tabbable[0];
|
||||
var tail = tabbable[tabbable.length - 1];
|
||||
var activeElement = getActiveElement();
|
||||
|
||||
// proceed with default browser behavior on tab.
|
||||
// Focus on last element on shift + tab.
|
||||
if (node === activeElement) {
|
||||
if (!shiftKey) return;
|
||||
target = tail;
|
||||
}
|
||||
|
||||
if (tail === activeElement && !shiftKey) {
|
||||
target = head;
|
||||
}
|
||||
|
||||
if (head === activeElement && shiftKey) {
|
||||
target = tail;
|
||||
}
|
||||
|
||||
if (target) {
|
||||
event.preventDefault();
|
||||
target.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Safari radio issue.
|
||||
//
|
||||
// Safari does not move the focus to the radio button,
|
||||
// so we need to force it to really walk through all elements.
|
||||
//
|
||||
// This is very error prone, since we are trying to guess
|
||||
// if it is a safari browser from the first occurence between
|
||||
// chrome or safari.
|
||||
//
|
||||
// The chrome user agent contains the first ocurrence
|
||||
// as the 'chrome/version' and later the 'safari/version'.
|
||||
var checkSafari = /(\bChrome\b|\bSafari\b)\//.exec(navigator.userAgent);
|
||||
var isSafariDesktop = checkSafari != null && checkSafari[1] != "Chrome" && /\biPod\b|\biPad\b/g.exec(navigator.userAgent) == null;
|
||||
|
||||
// If we are not in safari desktop, let the browser control
|
||||
// the focus
|
||||
if (!isSafariDesktop) return;
|
||||
|
||||
var x = tabbable.indexOf(activeElement);
|
||||
|
||||
if (x > -1) {
|
||||
x += shiftKey ? -1 : 1;
|
||||
}
|
||||
|
||||
target = tabbable[x];
|
||||
|
||||
// If the tabbable element does not exist,
|
||||
// focus head/tail based on shiftKey
|
||||
if (typeof target === "undefined") {
|
||||
event.preventDefault();
|
||||
target = shiftKey ? tail : head;
|
||||
target.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
target.focus();
|
||||
}
|
||||
module.exports = exports["default"];
|
||||
82
node_modules/react-modal/lib/helpers/tabbable.js
generated
vendored
Normal file
82
node_modules/react-modal/lib/helpers/tabbable.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = findTabbableDescendants;
|
||||
/*!
|
||||
* Adapted from jQuery UI core
|
||||
*
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright 2014 jQuery Foundation and other contributors
|
||||
* Released under the MIT license.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* http://api.jqueryui.com/category/ui-core/
|
||||
*/
|
||||
|
||||
var DISPLAY_NONE = "none";
|
||||
var DISPLAY_CONTENTS = "contents";
|
||||
|
||||
var tabbableNode = /input|select|textarea|button|object|iframe/;
|
||||
|
||||
function isNotOverflowing(element, style) {
|
||||
return style.getPropertyValue("overflow") !== "visible" ||
|
||||
// if 'overflow: visible' set, check if there is actually any overflow
|
||||
element.scrollWidth <= 0 && element.scrollHeight <= 0;
|
||||
}
|
||||
|
||||
function hidesContents(element) {
|
||||
var zeroSize = element.offsetWidth <= 0 && element.offsetHeight <= 0;
|
||||
|
||||
// If the node is empty, this is good enough
|
||||
if (zeroSize && !element.innerHTML) return true;
|
||||
|
||||
try {
|
||||
// Otherwise we need to check some styles
|
||||
var style = window.getComputedStyle(element);
|
||||
var displayValue = style.getPropertyValue("display");
|
||||
return zeroSize ? displayValue !== DISPLAY_CONTENTS && isNotOverflowing(element, style) : displayValue === DISPLAY_NONE;
|
||||
} catch (exception) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("Failed to inspect element style");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function visible(element) {
|
||||
var parentElement = element;
|
||||
var rootNode = element.getRootNode && element.getRootNode();
|
||||
while (parentElement) {
|
||||
if (parentElement === document.body) break;
|
||||
|
||||
// if we are not hidden yet, skip to checking outside the Web Component
|
||||
if (rootNode && parentElement === rootNode) parentElement = rootNode.host.parentNode;
|
||||
|
||||
if (hidesContents(parentElement)) return false;
|
||||
parentElement = parentElement.parentNode;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function focusable(element, isTabIndexNotNaN) {
|
||||
var nodeName = element.nodeName.toLowerCase();
|
||||
var res = tabbableNode.test(nodeName) && !element.disabled || (nodeName === "a" ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
|
||||
return res && visible(element);
|
||||
}
|
||||
|
||||
function tabbable(element) {
|
||||
var tabIndex = element.getAttribute("tabindex");
|
||||
if (tabIndex === null) tabIndex = undefined;
|
||||
var isTabIndexNaN = isNaN(tabIndex);
|
||||
return (isTabIndexNaN || tabIndex >= 0) && focusable(element, !isTabIndexNaN);
|
||||
}
|
||||
|
||||
function findTabbableDescendants(element) {
|
||||
var descendants = [].slice.call(element.querySelectorAll("*"), 0).reduce(function (finished, el) {
|
||||
return finished.concat(!el.shadowRoot ? [el] : findTabbableDescendants(el.shadowRoot));
|
||||
}, []);
|
||||
return descendants.filter(tabbable);
|
||||
}
|
||||
module.exports = exports["default"];
|
||||
Reference in New Issue
Block a user