react-responsive-modal 5.0.2 → 5.0.3
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/dist/modalManager.d.ts +6 -3
- package/dist/react-responsive-modal.cjs.development.js +22 -8
- package/dist/react-responsive-modal.cjs.development.js.map +1 -1
- package/dist/react-responsive-modal.cjs.production.min.js +1 -1
- package/dist/react-responsive-modal.cjs.production.min.js.map +1 -1
- package/dist/react-responsive-modal.esm.js +22 -8
- package/dist/react-responsive-modal.esm.js.map +1 -1
- package/package.json +18 -17
- package/src/index.tsx +1 -1
- package/src/modalManager.ts +7 -7
- package/src/utils.ts +3 -1
package/dist/modalManager.d.ts
CHANGED
|
@@ -2,15 +2,18 @@ declare const _default: {
|
|
|
2
2
|
/**
|
|
3
3
|
* Return the modals array
|
|
4
4
|
*/
|
|
5
|
-
modals: () =>
|
|
5
|
+
modals: () => {
|
|
6
|
+
element: HTMLDivElement;
|
|
7
|
+
blockScroll: boolean;
|
|
8
|
+
}[];
|
|
6
9
|
/**
|
|
7
10
|
* Register a new modal
|
|
8
11
|
*/
|
|
9
|
-
add: (
|
|
12
|
+
add: (newModal: HTMLDivElement, blockScroll: boolean) => void;
|
|
10
13
|
/**
|
|
11
14
|
* Remove a modal
|
|
12
15
|
*/
|
|
13
|
-
remove: (
|
|
16
|
+
remove: (oldModal: HTMLDivElement) => void;
|
|
14
17
|
/**
|
|
15
18
|
* Check if the modal is the first one on the screen
|
|
16
19
|
*/
|
|
@@ -71,17 +71,24 @@ var modalManager = {
|
|
|
71
71
|
/**
|
|
72
72
|
* Register a new modal
|
|
73
73
|
*/
|
|
74
|
-
add: function add(
|
|
75
|
-
if (_modals.
|
|
76
|
-
|
|
74
|
+
add: function add(newModal, blockScroll) {
|
|
75
|
+
if (_modals.findIndex(function (modal) {
|
|
76
|
+
return modal.element === newModal;
|
|
77
|
+
}) === -1) {
|
|
78
|
+
_modals.push({
|
|
79
|
+
element: newModal,
|
|
80
|
+
blockScroll: blockScroll
|
|
81
|
+
});
|
|
77
82
|
}
|
|
78
83
|
},
|
|
79
84
|
|
|
80
85
|
/**
|
|
81
86
|
* Remove a modal
|
|
82
87
|
*/
|
|
83
|
-
remove: function remove(
|
|
84
|
-
var index = _modals.
|
|
88
|
+
remove: function remove(oldModal) {
|
|
89
|
+
var index = _modals.findIndex(function (modal) {
|
|
90
|
+
return modal.element === oldModal;
|
|
91
|
+
});
|
|
85
92
|
|
|
86
93
|
if (index !== -1) {
|
|
87
94
|
_modals.splice(index, 1);
|
|
@@ -92,7 +99,9 @@ var modalManager = {
|
|
|
92
99
|
* Check if the modal is the first one on the screen
|
|
93
100
|
*/
|
|
94
101
|
isTopModal: function isTopModal(modal) {
|
|
95
|
-
|
|
102
|
+
var _modals2;
|
|
103
|
+
|
|
104
|
+
return !!_modals.length && ((_modals2 = _modals[_modals.length - 1]) === null || _modals2 === void 0 ? void 0 : _modals2.element) === modal;
|
|
96
105
|
}
|
|
97
106
|
};
|
|
98
107
|
|
|
@@ -102,7 +111,12 @@ var blockNoScroll = function blockNoScroll() {
|
|
|
102
111
|
};
|
|
103
112
|
var unblockNoScroll = function unblockNoScroll() {
|
|
104
113
|
// Restore the scroll only if there is no modal on the screen
|
|
105
|
-
|
|
114
|
+
// We filter the modals that are not affecting the scroll
|
|
115
|
+
var modals = modalManager.modals().filter(function (modal) {
|
|
116
|
+
return modal.blockScroll;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (modals.length === 0) {
|
|
106
120
|
noScroll.off();
|
|
107
121
|
}
|
|
108
122
|
};
|
|
@@ -280,7 +294,7 @@ var Modal = function Modal(_ref) {
|
|
|
280
294
|
setShowPortal = _useState[1];
|
|
281
295
|
|
|
282
296
|
var handleOpen = function handleOpen() {
|
|
283
|
-
modalManager.add(refContainer.current);
|
|
297
|
+
modalManager.add(refContainer.current, blockScroll);
|
|
284
298
|
|
|
285
299
|
if (blockScroll) {
|
|
286
300
|
blockNoScroll();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive-modal.cjs.development.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: any[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (modal: HTMLDivElement) => {\n if (modals.indexOf(modal) === -1) {\n modals.push(modal);\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (modal: HTMLDivElement) => {\n const index = modals.indexOf(modal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1] === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n if (modalManager.modals().length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classes","classNames","styles","id","closeIcon","onClickCloseIcon","React","className","cx","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","add","modal","indexOf","push","remove","index","splice","isTopModal","length","isBrowser","window","blockNoScroll","noScroll","on","unblockNoScroll","modalManager","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","tabTrappingKey","event","key","contains","process","console","warn","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","current","document","addEventListener","findIndex","selector","activeElement","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","blockScroll","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","body","appendChild","handleKeydown","handleClose","removeChild","keyCode","handleClickOverlay","handleModalEvent","handleClickCloseIcon","handleAnimationEnd","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAMA,SAAS,GAAG,SAAZA,SAAY;AAAA,MAChBC,OADgB,QAChBA,OADgB;AAAA,MAEhBC,UAFgB,QAEhBA,UAFgB;AAAA,MAGhBC,MAHgB,QAGhBA,MAHgB;AAAA,MAIhBC,EAJgB,QAIhBA,EAJgB;AAAA,MAKhBC,SALgB,QAKhBA,SALgB;AAAA,MAMhBC,gBANgB,QAMhBA,gBANgB;AAAA,SAQhBC,4BAAA,SAAA;AACEH,IAAAA,EAAE,EAA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IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAEsH;AAClBxH,IAAAA,EAAE,EAAE4F;GANN,CArBJ,CAdF,CADF,EA+CExB,SAAS,IAAIsC,YAAY,CAACjC,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
|
|
1
|
+
{"version":3,"file":"react-responsive-modal.cjs.development.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (newModal: HTMLDivElement, blockScroll: boolean) => {\n if (modals.findIndex((modal) => modal.element === newModal) === -1) {\n modals.push({ element: newModal, blockScroll });\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (oldModal: HTMLDivElement) => {\n const index = modals.findIndex((modal) => modal.element === oldModal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1]?.element === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n // We filter the modals that are not affecting the scroll\n const modals = modalManager.modals().filter((modal) => modal.blockScroll);\n if (modals.length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!, blockScroll);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classes","classNames","styles","id","closeIcon","onClickCloseIcon","React","className","cx","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","add","newModal","blockScroll","findIndex","modal","element","push","remove","oldModal","index","splice","isTopModal","length","isBrowser","window","blockNoScroll","noScroll","on","unblockNoScroll","modalManager","filter","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","tabTrappingKey","event","key","contains","process","console","warn","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","current","document","addEventListener","selector","activeElement","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","body","appendChild","handleKeydown","handleClose","removeChild","keyCode","handleClickOverlay","handleModalEvent","handleClickCloseIcon","handleAnimationEnd","ReactD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,IAAAA,SAAS,EAAEC,EAAE,CAACR,OAAO,CAACwF,OAAT,EAAkBvF,UAAlB,aAAkBA,UAAlB,uBAAkBA,UAAU,CAAEuF,OAA9B;AACb7E,IAAAA,OAAO,EAAEiH;AACThB,IAAAA,cAAc,EAAEmB;mBACJ;GAZd,EAcEzH,4BAAA,MAAA;AACE6H,IAAAA,GAAG,EAAErB;AACLvG,IAAAA,SAAS,EAAEC,EAAE,CACXR,OAAO,CAACsB,KADG,EAEXwE,MAAM,IAAI9F,OAAO,CAACyF,WAFP,EAGXxF,UAHW,aAGXA,UAHW,uBAGXA,UAAU,CAAEqB,KAHD;AAKbZ,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEoB;AACf8G,IAAAA,WAAW,EAAEP;AACbQ,IAAAA,SAAS,EAAER;AACXlH,IAAAA,OAAO,EAAEkH;AACT1H,IAAAA,EAAE,EAAEqG;AACJH,IAAAA,IAAI,EAAEA;kBACK;uBACME;wBACCD;mBACN;GAhBd,EAkBGH,YAAY,IAAI7F,4BAAA,CAACqE,SAAD;AAAWC,IAAAA,SAAS,EAAEkC;GAAtB,CAlBnB,EAmBGD,QAnBH,EAoBGZ,aAAa,IACZ3F,4BAAA,CAACP,SAAD;AACEC,IAAAA,OAAO,EAAEA;AACTC,IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAEyH;AAClB3H,IAAAA,EAAE,EAAE+F;GANN,CArBJ,CAdF,CADF,EA+CEtB,SAAS,IAAIoC,YAAY,CAAC/B,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),o=e(require("react-dom")),r=e(require("classnames")),l=e(require("no-scroll"));function a(){return(a=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n=require("react"),t=e(n),o=e(require("react-dom")),r=e(require("classnames")),l=e(require("no-scroll"));function a(){return(a=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var c=function(e){var n=e.classNames,o=e.styles,l=e.closeIcon,a=e.onClickCloseIcon;return t.createElement("button",{id:e.id,className:r(e.classes.closeButton,null==n?void 0:n.closeButton),style:null==o?void 0:o.closeButton,onClick:a,"data-testid":"close-button"},l||t.createElement("svg",{className:null==n?void 0:n.closeIcon,style:null==o?void 0:o.closeIcon,xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 36 36","data-testid":"close-icon"},t.createElement("path",{d:"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z"})))},i=[],u="undefined"!=typeof window,s=function(){0===i.filter((function(e){return e.blockScroll})).length&&l.off()},d=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])'];function v(e){return null===e.offsetParent||"hidden"===getComputedStyle(e).visibility}function f(e){for(var n=e.querySelectorAll(d.join(",")),t=[],o=0;o<n.length;o++){var r=n[o];!r.disabled&&m(r)>-1&&!v(r)&&t.push(r)}return t}function m(e){var n=parseInt(e.getAttribute("tabindex"),10);return isNaN(n)?function(e){return e.getAttribute("contentEditable")}(e)?0:e.tabIndex:n}var y=function(e){var t=e.container,o=n.useRef();return n.useEffect((function(){var e=function(e){(null==t?void 0:t.current)&&function(e,n){if(e&&"Tab"===e.key){if(!n||!n.contains)return process,!1;if(!n.contains(e.target))return!1;var t=f(n),o=t[0],r=t[t.length-1];e.shiftKey&&e.target===o?(r.focus(),e.preventDefault()):!e.shiftKey&&e.target===r&&(o.focus(),e.preventDefault())}}(e,t.current)};if(u&&document.addEventListener("keydown",e),u&&(null==t?void 0:t.current)){var n=f(t.current);n[0]&&(-1!==d.findIndex((function(e){var n;return null===(n=document.activeElement)||void 0===n?void 0:n.matches(e)}))&&(o.current=document.activeElement),n[0].focus())}return function(){var n;u&&(document.removeEventListener("keydown",e),null===(n=o.current)||void 0===n||n.focus())}}),[t]),null},p={overlay:"react-responsive-modal-overlay",modal:"react-responsive-modal-modal",modalCenter:"react-responsive-modal-modalCenter",closeButton:"react-responsive-modal-closeButton",animationIn:"react-responsive-modal-fadeIn",animationOut:"react-responsive-modal-fadeOut"},b=function(e){var d,v,f=e.open,m=e.center,b=e.blockScroll,h=void 0===b||b,E=e.closeOnEsc,I=void 0===E||E,g=e.closeOnOverlayClick,C=void 0===g||g,k=e.container,w=e.showCloseIcon,x=void 0===w||w,O=e.closeIconId,N=e.closeIcon,L=e.focusTrapped,B=void 0===L||L,D=e.animationDuration,S=void 0===D?500:D,j=e.classNames,q=e.styles,A=e.role,M=void 0===A?"dialog":A,P=e.ariaDescribedby,R=e.ariaLabelledby,K=e.modalId,T=e.onClose,_=e.onEscKeyDown,z=e.onOverlayClick,U=e.onAnimationEnd,F=e.children,G=n.useRef(null),H=n.useRef(null),J=n.useRef(null);null===J.current&&u&&(J.current=document.createElement("div"));var Q=n.useState(f),V=Q[0],W=Q[1],X=function(){(function(e,n){-1===i.findIndex((function(n){return n.element===e}))&&i.push({element:e,blockScroll:n})})(J.current,h),h&&l.on(),!J.current||k||document.body.contains(J.current)||document.body.appendChild(J.current),document.addEventListener("keydown",Z)},Y=function(){var e,n;e=J.current,-1!==(n=i.findIndex((function(n){return n.element===e})))&&i.splice(n,1),h&&s(),J.current&&!k&&document.body.contains(J.current)&&document.body.removeChild(J.current),document.removeEventListener("keydown",Z)},Z=function(e){var n;27===e.keyCode&&i.length&&(null===(n=i[i.length-1])||void 0===n?void 0:n.element)===J.current&&(_&&_(e),I&&T())};n.useEffect((function(){return f&&X(),function(){V&&Y()}}),[]),n.useEffect((function(){f&&!V&&(W(!0),X())}),[f]);var $=function(){H.current=!1};return V?o.createPortal(t.createElement("div",{style:a({animation:(f?null!==(d=null==j?void 0:j.animationIn)&&void 0!==d?d:p.animationIn:null!==(v=null==j?void 0:j.animationOut)&&void 0!==v?v:p.animationOut)+" "+S+"ms"},null==q?void 0:q.overlay),className:r(p.overlay,null==j?void 0:j.overlay),onClick:function(e){null===H.current&&(H.current=!0),H.current?(z&&z(e),C&&T(),H.current=null):H.current=null},onAnimationEnd:function(){f||(W(!1),Y()),h&&s(),U&&U()},"data-testid":"overlay"},t.createElement("div",{ref:G,className:r(p.modal,m&&p.modalCenter,null==j?void 0:j.modal),style:null==q?void 0:q.modal,onMouseDown:$,onMouseUp:$,onClick:$,id:K,role:M,"aria-modal":"true","aria-labelledby":R,"aria-describedby":P,"data-testid":"modal"},B&&t.createElement(y,{container:G}),F,x&&t.createElement(c,{classes:p,classNames:j,styles:q,closeIcon:N,onClickCloseIcon:function(){T()},id:O}))),k||J.current):null};exports.Modal=b,exports.default=b;
|
|
2
2
|
//# sourceMappingURL=react-responsive-modal.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive-modal.cjs.production.min.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: any[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (modal: HTMLDivElement) => {\n if (modals.indexOf(modal) === -1) {\n modals.push(modal);\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (modal: HTMLDivElement) => {\n const index = modals.indexOf(modal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1] === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n if (modalManager.modals().length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classNames","styles","closeIcon","onClickCloseIcon","React","id","className","cx","classes","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","isBrowser","window","unblockNoScroll","length","noScroll","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","push","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","event","current","key","contains","process","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabTrappingKey","document","addEventListener","findIndex","selector","activeElement","_document$activeEleme","matches","removeEventListener","overlay","modal","modalCenter","animationIn","animationOut","Modal","open","center","blockScroll","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","indexOf","on","body","appendChild","handleKeydown","handleClose","index","splice","removeChild","keyCode","handleModalEvent","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":"scAoBA,IAAMA,EAAY,gBAEhBC,IAAAA,WACAC,IAAAA,OAEAC,IAAAA,UACAC,IAAAA,wBAEAC,0BACEC,KALFA,GAMEC,UAAWC,IATbC,QASwBC,YAAaT,MAAAA,SAAAA,EAAYS,aAC/CC,MAAOT,MAAAA,SAAAA,EAAQQ,YACfE,QAASR,gBACG,gBAEXD,GAGCE,uBACEE,UAAWN,MAAAA,SAAAA,EAAYE,UACvBQ,MAAOT,MAAAA,SAAAA,EAAQC,UACfU,MAAM,6BACNC,MAAO,GACPC,OAAQ,GACRC,QAAQ,0BACI,cAEZX,wBAAMY,EAAE,2HC/CVC,EAAgB,GCGTC,EAA8B,oBAAXC,OAMnBC,EAAkB,WAEQ,IDDvBH,ECCYI,QACxBC,EAASC,OCVAC,EAAqB,CAChC,QACA,SACA,WACA,UACA,SACA,aACA,kBACA,kBACA,oDAGF,SAASC,EAASC,UAIQ,OAAtBA,EAAKC,cAA+D,WAAtCC,iBAAiBF,GAAMG,oBAIzCC,EAAsBC,WAChCC,EAAgBD,EAAWE,iBAAiBT,EAAmBU,KAAK,MACpEC,EAAe,GACVC,EAAI,EAAGA,EAAIJ,EAAcX,OAAQe,IAAK,KACzCV,EAAOM,EAAcI,IACp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ACXC,GAAc,GACdC,OAED,CAACzB,QAyBEoC,EAAmB,WACvBjB,EAAe7C,SAAU,UAsBpBiD,EACHc,EAASC,aACPjH,uBACEM,SACE4G,WACEvC,YACI/E,MAAAA,SAAAA,EAAY4E,2BAAepE,EAAQoE,sBACnC5E,MAAAA,SAAAA,EAAY6E,4BAAgBrE,EAAQqE,kBACtCU,QACDtF,MAAAA,SAAAA,EAAQwE,SAEbnE,UAAWC,EAAGC,EAAQiE,QAASzE,MAAAA,SAAAA,EAAYyE,SAC3C9D,QA1DmB,SACzByC,GAE+B,OAA3B8C,EAAe7C,UACjB6C,EAAe7C,SAAU,GAGtB6C,EAAe7C,SAKhByC,GACFA,EAAe1C,GAGb+B,GACFS,IAGFM,EAAe7C,QAAU,MAZvB6C,EAAe7C,QAAU,MAmDrB0C,eA5BmB,WACpBhB,IACHwB,GAAc,GACdO,KAGE7B,GACF7D,IAGE2E,GACFA,mBAkBgB,WAEZ3F,uBACEmH,IAAKtB,EACL3F,UAAWC,EACTC,EAAQkE,MACRM,GAAUxE,EAAQmE,YAClB3E,MAAAA,SAAAA,EAAY0E,OAEdhE,MAAOT,MAAAA,SAAAA,EAAQyE,MACf8C,YAAaL,EACbM,UAAWN,EACXxG,QAASwG,EACT9G,GAAIsF,EACJH,KAAMA,eACK,yBACME,qBACCD,gBACN,SAEXH,GAAgBlF,gBAAC0C,GAAUC,UAAWkD,IACtCD,EACAZ,GACChF,gBAACL,GACCS,QAASA,EACTR,WAAYA,EACZC,OAAQA,EACRC,UAAWA,EACXC,iBA7De,WAC3ByF,KA6DYvF,GAAIgF,MAKZtC,GAAaoD,EAAa9C,SAE5B"}
|
|
1
|
+
{"version":3,"file":"react-responsive-modal.cjs.production.min.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (newModal: HTMLDivElement, blockScroll: boolean) => {\n if (modals.findIndex((modal) => modal.element === newModal) === -1) {\n modals.push({ element: newModal, blockScroll });\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (oldModal: HTMLDivElement) => {\n const index = modals.findIndex((modal) => modal.element === oldModal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1]?.element === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n // We filter the modals that are not affecting the scroll\n const modals = modalManager.modals().filter((modal) => modal.blockScroll);\n if (modals.length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!, blockScroll);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classNames","styles","closeIcon","onClickCloseIcon","React","id","className","cx","classes","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","isBrowser","window","unblockNoScroll","filter","modal","blockScroll","length","noScroll","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","push","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","event","current","key","contains","process","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabTrappingKey","document","addEventListener","findIndex","selector","activeElement","_document$activeEleme","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","newModal","element","modalManager","on","body","appendChild","handleKeydown","handleClose","oldModal","index","splice","removeChild","keyCode","handleModalEvent","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":"scAoBA,IAAMA,EAAY,gBAEhBC,IAAAA,WACAC,IAAAA,OAEAC,IAAAA,UACAC,IAAAA,wBAEAC,0BACEC,KALFA,GAMEC,UAAWC,IATbC,QASwBC,YAAaT,MAAAA,SAAAA,EAAYS,aAC/CC,MAAOT,MAAAA,SAAAA,EAAQQ,YACfE,QAASR,gBACG,gBAEXD,GAGCE,uBACEE,UAAWN,MAAAA,SAAAA,EAAYE,UACvBQ,MAAOT,MAAAA,SAAAA,EAAQC,UACfU,MAAM,6BACNC,MAAO,GACPC,OAAQ,GACRC,QAAQ,0BACI,cAEZX,wBAAMY,EAAE,2HC/CVC,EAA8D,GCGvDC,EAA8B,oBAAXC,OAMnBC,EAAkB,WAIP,IDHRH,ECEuBI,QAAO,S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,QAAS4G,EACTlH,GAAIuF,EACJH,KAAMA,eACK,yBACME,qBACCD,gBACN,SAEXH,GAAgBnF,gBAAC6C,GAAUC,UAAWgD,IACtCD,EACAZ,GACCjF,gBAACL,GACCS,QAASA,EACTR,WAAYA,EACZC,OAAQA,EACRC,UAAWA,EACXC,iBA7De,WAC3B0F,KA6DYxF,GAAIiF,MAKZpC,GAAakD,EAAa5C,SAE5B"}
|
|
@@ -64,17 +64,24 @@ var modalManager = {
|
|
|
64
64
|
/**
|
|
65
65
|
* Register a new modal
|
|
66
66
|
*/
|
|
67
|
-
add: function add(
|
|
68
|
-
if (_modals.
|
|
69
|
-
|
|
67
|
+
add: function add(newModal, blockScroll) {
|
|
68
|
+
if (_modals.findIndex(function (modal) {
|
|
69
|
+
return modal.element === newModal;
|
|
70
|
+
}) === -1) {
|
|
71
|
+
_modals.push({
|
|
72
|
+
element: newModal,
|
|
73
|
+
blockScroll: blockScroll
|
|
74
|
+
});
|
|
70
75
|
}
|
|
71
76
|
},
|
|
72
77
|
|
|
73
78
|
/**
|
|
74
79
|
* Remove a modal
|
|
75
80
|
*/
|
|
76
|
-
remove: function remove(
|
|
77
|
-
var index = _modals.
|
|
81
|
+
remove: function remove(oldModal) {
|
|
82
|
+
var index = _modals.findIndex(function (modal) {
|
|
83
|
+
return modal.element === oldModal;
|
|
84
|
+
});
|
|
78
85
|
|
|
79
86
|
if (index !== -1) {
|
|
80
87
|
_modals.splice(index, 1);
|
|
@@ -85,7 +92,9 @@ var modalManager = {
|
|
|
85
92
|
* Check if the modal is the first one on the screen
|
|
86
93
|
*/
|
|
87
94
|
isTopModal: function isTopModal(modal) {
|
|
88
|
-
|
|
95
|
+
var _modals2;
|
|
96
|
+
|
|
97
|
+
return !!_modals.length && ((_modals2 = _modals[_modals.length - 1]) === null || _modals2 === void 0 ? void 0 : _modals2.element) === modal;
|
|
89
98
|
}
|
|
90
99
|
};
|
|
91
100
|
|
|
@@ -95,7 +104,12 @@ var blockNoScroll = function blockNoScroll() {
|
|
|
95
104
|
};
|
|
96
105
|
var unblockNoScroll = function unblockNoScroll() {
|
|
97
106
|
// Restore the scroll only if there is no modal on the screen
|
|
98
|
-
|
|
107
|
+
// We filter the modals that are not affecting the scroll
|
|
108
|
+
var modals = modalManager.modals().filter(function (modal) {
|
|
109
|
+
return modal.blockScroll;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (modals.length === 0) {
|
|
99
113
|
noScroll.off();
|
|
100
114
|
}
|
|
101
115
|
};
|
|
@@ -273,7 +287,7 @@ var Modal = function Modal(_ref) {
|
|
|
273
287
|
setShowPortal = _useState[1];
|
|
274
288
|
|
|
275
289
|
var handleOpen = function handleOpen() {
|
|
276
|
-
modalManager.add(refContainer.current);
|
|
290
|
+
modalManager.add(refContainer.current, blockScroll);
|
|
277
291
|
|
|
278
292
|
if (blockScroll) {
|
|
279
293
|
blockNoScroll();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-responsive-modal.esm.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: any[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (modal: HTMLDivElement) => {\n if (modals.indexOf(modal) === -1) {\n modals.push(modal);\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (modal: HTMLDivElement) => {\n const index = modals.indexOf(modal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1] === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n if (modalManager.modals().length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classes","classNames","styles","id","closeIcon","onClickCloseIcon","React","className","cx","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","add","modal","indexOf","push","remove","index","splice","isTopModal","length","isBrowser","window","blockNoScroll","noScroll","on","unblockNoScroll","modalManager","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","tabTrappingKey","event","key","contains","process","env","NODE_ENV","console","warn","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","current","document","addEventListener","findIndex","selector","activeElement","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","blockScroll","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","body","appendChild","handleKeydown","handleClose","removeChild","keyCode","handleClickOverlay","handleModalEvent","handleClickCloseIcon","handleAnimationEnd","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAMA,SAAS,GAAG,SAAZA,SAAY;AAAA,MAChBC,OADgB,QAChBA,OADgB;AAAA,MAEhBC,UAFgB,QAEhBA,UAFgB;AAAA,MAGhBC,MAHgB,QAGhBA,MAHgB;AAAA,MAIhBC,EAJgB,QAIhBA,EAJgB;AAAA,MAKhBC,SALgB,QAKhBA,SALgB;AAAA,MAMhBC,gBANgB,QAMhBA,gBANgB;AAAA,SAQhBC,mBAAA,SAAA;AACEH,IAAAA,EAAE,EAAEA;AACJI,IAAAA,SAAS,EAAEC,EAAE,CAACR,OAAO,CAACS,WAAT,EAAsBR,UAAtB,aAAsBA,UAAtB,uBAAsBA,UAAU,CAAEQ,WAAlC;AACbC,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEO;AACfE,IAAAA,OAAO,EAAEN;mBACG;GALd,EAOGD,SAAS,GACRA,SADQ,GAGRE,mBAAA,MAAA;AACEC,IAAAA,SAAS,EAAEN,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAEG;AACvBM,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEE;AACfQ,IAAAA,KAAK,EAAC;AACNC,IAAAA,KAAK,EAAE;AACPC,IAAAA,MAAM,EAAE;AACRC,IAAAA,OAAO,EAAC;mBACI;GAPd,EASET,mBAAA,OAAA;AAAMU,IAAAA,CAAC,EAAC;GAAR,CATF,CAVJ,CARgB;AAAA,CAAlB;;ACpBA,IAAMC,OAAM,GAAU,EAAtB;AAEA;;;;;AAIA,mBAAe;AACb;;;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A,GAAG,EAAErB;AACLtG,IAAAA,SAAS,EAAEC,EAAE,CACXR,OAAO,CAACmB,KADG,EAEXyE,MAAM,IAAI5F,OAAO,CAACuF,WAFP,EAGXtF,UAHW,aAGXA,UAHW,uBAGXA,UAAU,CAAEkB,KAHD;AAKbT,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEiB;AACfgH,IAAAA,WAAW,EAAEP;AACbQ,IAAAA,SAAS,EAAER;AACXjH,IAAAA,OAAO,EAAEiH;AACTzH,IAAAA,EAAE,EAAEoG;AACJH,IAAAA,IAAI,EAAEA;kBACK;uBACME;wBACCD;mBACN;GAhBd,EAkBGH,YAAY,IAAI5F,mBAAA,CAACkE,SAAD;AAAWC,IAAAA,SAAS,EAAEoC;GAAtB,CAlBnB,EAmBGD,QAnBH,EAoBGZ,aAAa,IACZ1F,mBAAA,CAACP,SAAD;AACEC,IAAAA,OAAO,EAAEA;AACTC,IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAEwH;AAClB1H,IAAAA,EAAE,EAAE8F;GANN,CArBJ,CAdF,CADF,EA+CExB,SAAS,IAAIsC,YAAY,CAACjC,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
|
|
1
|
+
{"version":3,"file":"react-responsive-modal.esm.js","sources":["../src/CloseIcon.tsx","../src/modalManager.ts","../src/utils.ts","../src/focusTrapJs.ts","../src/FocusTrap.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport cx from 'classnames';\n\ninterface CloseIconProps {\n id?: string;\n closeIcon?: React.ReactNode;\n styles?: {\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n classNames?: {\n closeButton?: string;\n closeIcon?: string;\n };\n classes: {\n closeButton?: string;\n };\n onClickCloseIcon: () => void;\n}\n\nconst CloseIcon = ({\n classes,\n classNames,\n styles,\n id,\n closeIcon,\n onClickCloseIcon,\n}: CloseIconProps) => (\n <button\n id={id}\n className={cx(classes.closeButton, classNames?.closeButton)}\n style={styles?.closeButton}\n onClick={onClickCloseIcon}\n data-testid=\"close-button\"\n >\n {closeIcon ? (\n closeIcon\n ) : (\n <svg\n className={classNames?.closeIcon}\n style={styles?.closeIcon}\n xmlns=\"http://www.w3.org/2000/svg\"\n width={28}\n height={28}\n viewBox=\"0 0 36 36\"\n data-testid=\"close-icon\"\n >\n <path d=\"M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z\" />\n </svg>\n )}\n </button>\n);\n\nexport default CloseIcon;\n","const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];\n\n/**\n * Handle the order of the modals.\n * Inspired by the material-ui implementation.\n */\nexport default {\n /**\n * Return the modals array\n */\n modals: () => modals,\n\n /**\n * Register a new modal\n */\n add: (newModal: HTMLDivElement, blockScroll: boolean) => {\n if (modals.findIndex((modal) => modal.element === newModal) === -1) {\n modals.push({ element: newModal, blockScroll });\n }\n },\n\n /**\n * Remove a modal\n */\n remove: (oldModal: HTMLDivElement) => {\n const index = modals.findIndex((modal) => modal.element === oldModal);\n if (index !== -1) {\n modals.splice(index, 1);\n }\n },\n\n /**\n * Check if the modal is the first one on the screen\n */\n isTopModal: (modal: HTMLDivElement) =>\n !!modals.length && modals[modals.length - 1]?.element === modal,\n};\n","import noScroll from 'no-scroll';\nimport modalManager from './modalManager';\n\nexport const isBrowser = typeof window !== 'undefined';\n\nexport const blockNoScroll = () => {\n noScroll.on();\n};\n\nexport const unblockNoScroll = () => {\n // Restore the scroll only if there is no modal on the screen\n // We filter the modals that are not affecting the scroll\n const modals = modalManager.modals().filter((modal) => modal.blockScroll);\n if (modals.length === 0) {\n noScroll.off();\n }\n};\n","// https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9\n\nexport const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n];\n\nfunction isHidden(node: any) {\n // offsetParent being null will allow detecting cases where an element is invisible or inside an invisible element,\n // as long as the element does not use position: fixed. For them, their visibility has to be checked directly as well.\n return (\n node.offsetParent === null || getComputedStyle(node).visibility === 'hidden'\n );\n}\n\nexport function getAllTabbingElements(parentElem: any) {\n var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));\n var onlyTabbable = [];\n for (var i = 0; i < tabbableNodes.length; i++) {\n var node = tabbableNodes[i];\n if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {\n onlyTabbable.push(node);\n }\n }\n return onlyTabbable;\n}\n\nexport function tabTrappingKey(event: any, parentElem: any) {\n // check if current event keyCode is tab\n if (!event || event.key !== 'Tab') return;\n\n if (!parentElem || !parentElem.contains) {\n if (process && process.env.NODE_ENV === 'development') {\n console.warn('focus-trap-js: parent element is not defined');\n }\n return false;\n }\n\n if (!parentElem.contains(event.target)) {\n return false;\n }\n\n var allTabbingElements = getAllTabbingElements(parentElem);\n var firstFocusableElement = allTabbingElements[0];\n var lastFocusableElement = allTabbingElements[allTabbingElements.length - 1];\n\n if (event.shiftKey && event.target === firstFocusableElement) {\n lastFocusableElement.focus();\n event.preventDefault();\n return true;\n } else if (!event.shiftKey && event.target === lastFocusableElement) {\n firstFocusableElement.focus();\n event.preventDefault();\n return true;\n }\n return false;\n}\n\nfunction getTabindex(node: any) {\n var tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) return tabindexAttr;\n // Browsers do not return tabIndex correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n\n if (isContentEditable(node)) return 0;\n return node.tabIndex;\n}\n\nfunction isContentEditable(node: any) {\n return node.getAttribute('contentEditable');\n}\n","import { useEffect, useRef } from 'react';\nimport { isBrowser } from './utils';\nimport {\n tabTrappingKey,\n candidateSelectors,\n getAllTabbingElements,\n} from './focusTrapJs';\n\ninterface FocusTrapProps {\n container?: React.RefObject<HTMLElement> | null;\n}\n\nexport const FocusTrap = ({ container }: FocusTrapProps) => {\n const refLastFocus = useRef<HTMLElement | null>();\n /**\n * Handle focus lock on the modal\n */\n useEffect(() => {\n const handleKeyEvent = (event: KeyboardEvent) => {\n if (container?.current) {\n tabTrappingKey(event, container.current);\n }\n };\n\n if (isBrowser) {\n document.addEventListener('keydown', handleKeyEvent);\n }\n // On mount we focus on the first focusable element in the modal if there is one\n if (isBrowser && container?.current) {\n const allTabbingElements = getAllTabbingElements(container.current);\n if (allTabbingElements[0]) {\n // First we save the last focused element\n // only if it's a focusable element\n if (\n candidateSelectors.findIndex((selector) =>\n document.activeElement?.matches(selector)\n ) !== -1\n ) {\n refLastFocus.current = document.activeElement as HTMLElement;\n }\n allTabbingElements[0].focus();\n }\n }\n return () => {\n if (isBrowser) {\n document.removeEventListener('keydown', handleKeyEvent);\n // On unmount we restore the focus to the last focused element\n refLastFocus.current?.focus();\n }\n };\n }, [container]);\n\n return null;\n};\n","import React, { useEffect, useState, useRef } from 'react';\nimport ReactDom from 'react-dom';\nimport cx from 'classnames';\nimport CloseIcon from './CloseIcon';\nimport { FocusTrap } from './FocusTrap';\nimport modalManager from './modalManager';\nimport { isBrowser, blockNoScroll, unblockNoScroll } from './utils';\n\nconst classes = {\n overlay: 'react-responsive-modal-overlay',\n modal: 'react-responsive-modal-modal',\n modalCenter: 'react-responsive-modal-modalCenter',\n closeButton: 'react-responsive-modal-closeButton',\n animationIn: 'react-responsive-modal-fadeIn',\n animationOut: 'react-responsive-modal-fadeOut',\n};\n\ninterface ModalProps {\n /**\n * Control if the modal is open or not.\n */\n open: boolean;\n /**\n * Should the dialog be centered.\n *\n * Default to false.\n */\n center?: boolean;\n /**\n * Is the modal closable when user press esc key.\n *\n * Default to true.\n */\n closeOnEsc?: boolean;\n /**\n * Is the modal closable when user click on overlay.\n *\n * Default to true.\n */\n closeOnOverlayClick?: boolean;\n /**\n * Whether to block scrolling when dialog is open.\n *\n * Default to true.\n */\n blockScroll?: boolean;\n /**\n * Show the close icon.\n */\n showCloseIcon?: boolean;\n /**\n * id attribute for the close icon button.\n */\n closeIconId?: string;\n /**\n * Custom icon to render (svg, img, etc...).\n */\n closeIcon?: React.ReactNode;\n /**\n * When the modal is open, trap focus within it.\n *\n * Default to true.\n */\n focusTrapped?: boolean;\n /**\n * You can specify a container prop which should be of type `Element`.\n * The portal will be rendered inside that element.\n * The default behavior will create a div node and render it at the at the end of document.body.\n */\n container?: Element;\n /**\n * An object containing classNames to style the modal.\n */\n classNames?: {\n overlay?: string;\n modal?: string;\n closeButton?: string;\n closeIcon?: string;\n animationIn?: string;\n animationOut?: string;\n };\n /**\n * An object containing the styles objects to style the modal.\n */\n styles?: {\n overlay?: React.CSSProperties;\n modal?: React.CSSProperties;\n closeButton?: React.CSSProperties;\n closeIcon?: React.CSSProperties;\n };\n /**\n * Animation duration in milliseconds.\n *\n * Default to 500.\n */\n animationDuration?: number;\n /**\n * ARIA role for modal\n *\n * Default to 'dialog'.\n */\n role?: string;\n /**\n * ARIA label for modal\n */\n ariaLabelledby?: string;\n /**\n * ARIA description for modal\n */\n ariaDescribedby?: string;\n /**\n * id attribute for modal\n */\n modalId?: string;\n /**\n * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.\n */\n onClose: () => void;\n /**\n * Callback fired when the escape key is pressed.\n */\n onEscKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Callback fired when the overlay is clicked.\n */\n onOverlayClick?: (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => void;\n /**\n * Callback fired when the Modal has exited and the animation is finished.\n */\n onAnimationEnd?: () => void;\n children?: React.ReactNode;\n}\n\nexport const Modal = ({\n open,\n center,\n blockScroll = true,\n closeOnEsc = true,\n closeOnOverlayClick = true,\n container,\n showCloseIcon = true,\n closeIconId,\n closeIcon,\n focusTrapped = true,\n animationDuration = 500,\n classNames,\n styles,\n role = 'dialog',\n ariaDescribedby,\n ariaLabelledby,\n modalId,\n onClose,\n onEscKeyDown,\n onOverlayClick,\n onAnimationEnd,\n children,\n}: ModalProps) => {\n const refModal = useRef<HTMLDivElement>(null);\n const refShouldClose = useRef<boolean | null>(null);\n const refContainer = useRef<HTMLDivElement | null>(null);\n // Lazily create the ref instance\n // https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n if (refContainer.current === null && isBrowser) {\n refContainer.current = document.createElement('div');\n }\n\n const [showPortal, setShowPortal] = useState(open);\n\n const handleOpen = () => {\n modalManager.add(refContainer.current!, blockScroll);\n if (blockScroll) {\n blockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n !document.body.contains(refContainer.current)\n ) {\n document.body.appendChild(refContainer.current);\n }\n document.addEventListener('keydown', handleKeydown);\n };\n\n const handleClose = () => {\n modalManager.remove(refContainer.current!);\n if (blockScroll) {\n unblockNoScroll();\n }\n if (\n refContainer.current &&\n !container &&\n document.body.contains(refContainer.current)\n ) {\n document.body.removeChild(refContainer.current);\n }\n document.removeEventListener('keydown', handleKeydown);\n };\n\n const handleKeydown = (event: KeyboardEvent) => {\n // Only the last modal need to be escaped when pressing the esc key\n if (\n event.keyCode !== 27 ||\n !modalManager.isTopModal(refContainer.current!)\n ) {\n return;\n }\n\n if (onEscKeyDown) {\n onEscKeyDown(event);\n }\n\n if (closeOnEsc) {\n onClose();\n }\n };\n\n useEffect(() => {\n // When the modal is rendered first time we want to block the scroll\n if (open) {\n handleOpen();\n }\n return () => {\n // When the component is unmounted directly we want to unblock the scroll\n if (showPortal) {\n handleClose();\n }\n };\n }, []);\n\n useEffect(() => {\n // If the open prop is changing, we need to open the modal\n if (open && !showPortal) {\n setShowPortal(true);\n handleOpen();\n }\n }, [open]);\n\n const handleClickOverlay = (\n event: React.MouseEvent<HTMLDivElement, MouseEvent>\n ) => {\n if (refShouldClose.current === null) {\n refShouldClose.current = true;\n }\n\n if (!refShouldClose.current) {\n refShouldClose.current = null;\n return;\n }\n\n if (onOverlayClick) {\n onOverlayClick(event);\n }\n\n if (closeOnOverlayClick) {\n onClose();\n }\n\n refShouldClose.current = null;\n };\n\n const handleModalEvent = () => {\n refShouldClose.current = false;\n };\n\n const handleClickCloseIcon = () => {\n onClose();\n };\n\n const handleAnimationEnd = () => {\n if (!open) {\n setShowPortal(false);\n handleClose();\n }\n\n if (blockScroll) {\n unblockNoScroll();\n }\n\n if (onAnimationEnd) {\n onAnimationEnd();\n }\n };\n\n return showPortal\n ? ReactDom.createPortal(\n <div\n style={{\n animation: `${\n open\n ? classNames?.animationIn ?? classes.animationIn\n : classNames?.animationOut ?? classes.animationOut\n } ${animationDuration}ms`,\n ...styles?.overlay,\n }}\n className={cx(classes.overlay, classNames?.overlay)}\n onClick={handleClickOverlay}\n onAnimationEnd={handleAnimationEnd}\n data-testid=\"overlay\"\n >\n <div\n ref={refModal}\n className={cx(\n classes.modal,\n center && classes.modalCenter,\n classNames?.modal\n )}\n style={styles?.modal}\n onMouseDown={handleModalEvent}\n onMouseUp={handleModalEvent}\n onClick={handleModalEvent}\n id={modalId}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n data-testid=\"modal\"\n >\n {focusTrapped && <FocusTrap container={refModal} />}\n {children}\n {showCloseIcon && (\n <CloseIcon\n classes={classes}\n classNames={classNames}\n styles={styles}\n closeIcon={closeIcon}\n onClickCloseIcon={handleClickCloseIcon}\n id={closeIconId}\n />\n )}\n </div>\n </div>,\n container || refContainer.current!\n )\n : null;\n};\n\nexport default Modal;\n"],"names":["CloseIcon","classes","classNames","styles","id","closeIcon","onClickCloseIcon","React","className","cx","closeButton","style","onClick","xmlns","width","height","viewBox","d","modals","add","newModal","blockScroll","findIndex","modal","element","push","remove","oldModal","index","splice","isTopModal","length","isBrowser","window","blockNoScroll","noScroll","on","unblockNoScroll","modalManager","filter","off","candidateSelectors","isHidden","node","offsetParent","getComputedStyle","visibility","getAllTabbingElements","parentElem","tabbableNodes","querySelectorAll","join","onlyTabbable","i","disabled","getTabindex","tabTrappingKey","event","key","contains","process","env","NODE_ENV","console","warn","target","allTabbingElements","firstFocusableElement","lastFocusableElement","shiftKey","focus","preventDefault","tabindexAttr","parseInt","getAttribute","isNaN","isContentEditable","tabIndex","FocusTrap","container","refLastFocus","useRef","useEffect","handleKeyEvent","current","document","addEventListener","selector","activeElement","matches","removeEventListener","overlay","modalCenter","animationIn","animationOut","Modal","open","center","closeOnEsc","closeOnOverlayClick","showCloseIcon","closeIconId","focusTrapped","animationDuration","role","ariaDescribedby","ariaLabelledby","modalId","onClose","onEscKeyDown","onOverlayClick","onAnimationEnd","children","refModal","refShouldClose","refContainer","createElement","useState","showPortal","setShowPortal","handleOpen","body","appendChild","handleKeydown","handleClose","removeChild","keyCode","handleClickOverlay","handleModalEvent","handleClickCloseIcon","handleAnimationEnd","ReactDom","createPortal","animation","ref","onMouseDown","onMouseUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoBA,IAAMA,SAAS,GAAG,SAAZA,SAAY;AAAA,MAChBC,OADgB,QAChBA,OADgB;AAAA,MAEhBC,UAFgB,QAEhBA,UAFgB;AAAA,MAGhBC,MAHgB,QAGhBA,MAHgB;AAAA,MAIhBC,EAJgB,QAIhBA,EAJgB;AAAA,MAKhBC,SALgB,QAKhBA,SALgB;AAAA,MAMhBC,gBANgB,QAMhBA,gBANgB;AAAA,SAQhBC,mBAAA,SAAA;AACEH,IAAAA,EAAE,EAAEA;AACJI,IAAAA,SAAS,EAAEC,EAAE,CAACR,OAAO,CAACS,WAAT,EAAsBR,UAAtB,aAAsBA,UAAtB,uBAAsBA,UAAU,CAAEQ,WAAlC;AACbC,IAAAA,KAAK,EAAER,MAAF,aAAEA,MAAF,uBAAEA,MAAM,CAAEO;AACfE,IAAAA,OAAO,EAAEN;mBACG;GALd,EAOGD,SAAS,GACRA,SADQ,GAGRE,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wBACCD;mBACN;GAhBd,EAkBGH,YAAY,IAAI/F,mBAAA,CAACuE,SAAD;AAAWC,IAAAA,SAAS,EAAEkC;GAAtB,CAlBnB,EAmBGD,QAnBH,EAoBGZ,aAAa,IACZ7F,mBAAA,CAACP,SAAD;AACEC,IAAAA,OAAO,EAAEA;AACTC,IAAAA,UAAU,EAAEA;AACZC,IAAAA,MAAM,EAAEA;AACRE,IAAAA,SAAS,EAAEA;AACXC,IAAAA,gBAAgB,EAAE2H;AAClB7H,IAAAA,EAAE,EAAEiG;GANN,CArBJ,CAdF,CADF,EA+CEtB,SAAS,IAAIoC,YAAY,CAAC/B,OA/C5B,CADa,GAkDb,IAlDJ;AAmDD,CAzMM;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-responsive-modal",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "A simple responsive and accessible react modal compatible with React 16 and ready for React 17",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -63,25 +63,26 @@
|
|
|
63
63
|
"react-dom": "^16.8.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@testing-library/
|
|
69
|
-
"@testing-library/react": "10.0.2",
|
|
66
|
+
"@size-limit/preset-small-lib": "4.5.6",
|
|
67
|
+
"@testing-library/jest-dom": "5.11.3",
|
|
68
|
+
"@testing-library/react": "10.4.8",
|
|
70
69
|
"@types/classnames": "2.2.10",
|
|
71
|
-
"@types/jest": "25.2.1",
|
|
72
70
|
"@types/no-scroll": "2.1.0",
|
|
73
|
-
"@types/
|
|
74
|
-
"@types/react
|
|
75
|
-
"@types/react-
|
|
76
|
-
"
|
|
71
|
+
"@types/node": "14.0.27",
|
|
72
|
+
"@types/react": "16.9.39",
|
|
73
|
+
"@types/react-dom": "16.9.8",
|
|
74
|
+
"@types/react-transition-group": "4.4.0",
|
|
75
|
+
"codecov": "3.7.2",
|
|
77
76
|
"docz": "2.3.1",
|
|
78
|
-
"
|
|
79
|
-
"
|
|
77
|
+
"gatsby": "2.23.11",
|
|
78
|
+
"gatsby-theme-docz": "2.3.1",
|
|
79
|
+
"husky": "4.2.5",
|
|
80
|
+
"prettier": "2.0.5",
|
|
80
81
|
"react": "16.13.1",
|
|
81
82
|
"react-dom": "16.13.1",
|
|
82
|
-
"size-limit": "4.
|
|
83
|
-
"tsdx": "0.13.
|
|
84
|
-
"tslib": "
|
|
85
|
-
"typescript": "3.
|
|
83
|
+
"size-limit": "4.5.6",
|
|
84
|
+
"tsdx": "0.13.2",
|
|
85
|
+
"tslib": "2.0.1",
|
|
86
|
+
"typescript": "^3.9.7"
|
|
86
87
|
}
|
|
87
|
-
}
|
|
88
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -169,7 +169,7 @@ export const Modal = ({
|
|
|
169
169
|
const [showPortal, setShowPortal] = useState(open);
|
|
170
170
|
|
|
171
171
|
const handleOpen = () => {
|
|
172
|
-
modalManager.add(refContainer.current
|
|
172
|
+
modalManager.add(refContainer.current!, blockScroll);
|
|
173
173
|
if (blockScroll) {
|
|
174
174
|
blockNoScroll();
|
|
175
175
|
}
|
package/src/modalManager.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const modals:
|
|
1
|
+
const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Handle the order of the modals.
|
|
@@ -13,17 +13,17 @@ export default {
|
|
|
13
13
|
/**
|
|
14
14
|
* Register a new modal
|
|
15
15
|
*/
|
|
16
|
-
add: (
|
|
17
|
-
if (modals.
|
|
18
|
-
modals.push(
|
|
16
|
+
add: (newModal: HTMLDivElement, blockScroll: boolean) => {
|
|
17
|
+
if (modals.findIndex((modal) => modal.element === newModal) === -1) {
|
|
18
|
+
modals.push({ element: newModal, blockScroll });
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Remove a modal
|
|
24
24
|
*/
|
|
25
|
-
remove: (
|
|
26
|
-
const index = modals.
|
|
25
|
+
remove: (oldModal: HTMLDivElement) => {
|
|
26
|
+
const index = modals.findIndex((modal) => modal.element === oldModal);
|
|
27
27
|
if (index !== -1) {
|
|
28
28
|
modals.splice(index, 1);
|
|
29
29
|
}
|
|
@@ -33,5 +33,5 @@ export default {
|
|
|
33
33
|
* Check if the modal is the first one on the screen
|
|
34
34
|
*/
|
|
35
35
|
isTopModal: (modal: HTMLDivElement) =>
|
|
36
|
-
!!modals.length && modals[modals.length - 1] === modal,
|
|
36
|
+
!!modals.length && modals[modals.length - 1]?.element === modal,
|
|
37
37
|
};
|
package/src/utils.ts
CHANGED
|
@@ -9,7 +9,9 @@ export const blockNoScroll = () => {
|
|
|
9
9
|
|
|
10
10
|
export const unblockNoScroll = () => {
|
|
11
11
|
// Restore the scroll only if there is no modal on the screen
|
|
12
|
-
|
|
12
|
+
// We filter the modals that are not affecting the scroll
|
|
13
|
+
const modals = modalManager.modals().filter((modal) => modal.blockScroll);
|
|
14
|
+
if (modals.length === 0) {
|
|
13
15
|
noScroll.off();
|
|
14
16
|
}
|
|
15
17
|
};
|