New source found from dndbeyond.com
This commit is contained in:
+28
-12
@@ -58,8 +58,17 @@ var CLASS_NAMES = {
|
||||
content: "ReactModal__Content"
|
||||
};
|
||||
|
||||
var TAB_KEY = 9;
|
||||
var ESC_KEY = 27;
|
||||
/**
|
||||
* We need to support the deprecated `KeyboardEvent.keyCode` in addition to
|
||||
* `KeyboardEvent.code` for apps that still support IE11. Can be removed when
|
||||
* `react-modal` only supports React >18 (which dropped IE support).
|
||||
*/
|
||||
var isTabKey = function isTabKey(event) {
|
||||
return event.code === "Tab" || event.keyCode === 9;
|
||||
};
|
||||
var isEscKey = function isEscKey(event) {
|
||||
return event.code === "Escape" || event.keyCode === 27;
|
||||
};
|
||||
|
||||
var ariaHiddenInstances = 0;
|
||||
|
||||
@@ -86,13 +95,16 @@ var ModalPortal = function (_Component) {
|
||||
appElement = _this$props.appElement,
|
||||
ariaHideApp = _this$props.ariaHideApp,
|
||||
htmlOpenClassName = _this$props.htmlOpenClassName,
|
||||
bodyOpenClassName = _this$props.bodyOpenClassName;
|
||||
bodyOpenClassName = _this$props.bodyOpenClassName,
|
||||
parentSelector = _this$props.parentSelector;
|
||||
|
||||
|
||||
var parentDocument = parentSelector && parentSelector().ownerDocument || document;
|
||||
|
||||
// Remove classes.
|
||||
bodyOpenClassName && classList.remove(parentDocument.body, bodyOpenClassName);
|
||||
|
||||
bodyOpenClassName && classList.remove(document.body, bodyOpenClassName);
|
||||
|
||||
htmlOpenClassName && classList.remove(document.getElementsByTagName("html")[0], htmlOpenClassName);
|
||||
htmlOpenClassName && classList.remove(parentDocument.getElementsByTagName("html")[0], htmlOpenClassName);
|
||||
|
||||
// Reset aria-hidden attribute if all modals have been removed
|
||||
if (ariaHideApp && ariaHiddenInstances > 0) {
|
||||
@@ -174,11 +186,11 @@ var ModalPortal = function (_Component) {
|
||||
};
|
||||
|
||||
_this.handleKeyDown = function (event) {
|
||||
if (event.keyCode === TAB_KEY) {
|
||||
if (isTabKey(event)) {
|
||||
(0, _scopeTab2.default)(_this.content, event);
|
||||
}
|
||||
|
||||
if (_this.props.shouldCloseOnEsc && event.keyCode === ESC_KEY) {
|
||||
if (_this.props.shouldCloseOnEsc && isEscKey(event)) {
|
||||
event.stopPropagation();
|
||||
_this.requestClose(event);
|
||||
}
|
||||
@@ -314,13 +326,16 @@ var ModalPortal = function (_Component) {
|
||||
appElement = _props.appElement,
|
||||
ariaHideApp = _props.ariaHideApp,
|
||||
htmlOpenClassName = _props.htmlOpenClassName,
|
||||
bodyOpenClassName = _props.bodyOpenClassName;
|
||||
bodyOpenClassName = _props.bodyOpenClassName,
|
||||
parentSelector = _props.parentSelector;
|
||||
|
||||
|
||||
var parentDocument = parentSelector && parentSelector().ownerDocument || document;
|
||||
|
||||
// Add classes.
|
||||
bodyOpenClassName && classList.add(parentDocument.body, bodyOpenClassName);
|
||||
|
||||
bodyOpenClassName && classList.add(document.body, bodyOpenClassName);
|
||||
|
||||
htmlOpenClassName && classList.add(document.getElementsByTagName("html")[0], htmlOpenClassName);
|
||||
htmlOpenClassName && classList.add(parentDocument.getElementsByTagName("html")[0], htmlOpenClassName);
|
||||
|
||||
if (ariaHideApp) {
|
||||
ariaHiddenInstances += 1;
|
||||
@@ -400,6 +415,7 @@ ModalPortal.propTypes = {
|
||||
}),
|
||||
className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
|
||||
overlayClassName: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]),
|
||||
parentSelector: _propTypes2.default.func,
|
||||
bodyOpenClassName: _propTypes2.default.string,
|
||||
htmlOpenClassName: _propTypes2.default.string,
|
||||
ariaHideApp: _propTypes2.default.bool,
|
||||
|
||||
+13
-4
@@ -16,7 +16,17 @@ exports.default = findTabbableDescendants;
|
||||
* http://api.jqueryui.com/category/ui-core/
|
||||
*/
|
||||
|
||||
var tabbableNode = /input|select|textarea|button|object/;
|
||||
var DISPLAY_NONE = "none";
|
||||
var DISPLAY_CONTENTS = "contents";
|
||||
|
||||
// match the whole word to prevent fuzzy searching
|
||||
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;
|
||||
@@ -27,9 +37,8 @@ function hidesContents(element) {
|
||||
try {
|
||||
// Otherwise we need to check some styles
|
||||
var style = window.getComputedStyle(element);
|
||||
return zeroSize ? style.getPropertyValue("overflow") !== "visible" ||
|
||||
// if 'overflow: visible' set, check if there is actually any overflow
|
||||
element.scrollWidth <= 0 && element.scrollHeight <= 0 : style.getPropertyValue("display") == "none";
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user