react-responsive-modal 5.2.6 → 6.2.0

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.
@@ -1,4 +1,4 @@
1
- // https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.0.9
1
+ // https://github.com/alexandrzavalii/focus-trap-js/blob/master/src/index.js v1.1.0
2
2
 
3
3
  export const candidateSelectors = [
4
4
  'input',
@@ -20,12 +20,39 @@ function isHidden(node: any) {
20
20
  );
21
21
  }
22
22
 
23
+ function getCheckedRadio(nodes: any, form: any) {
24
+ for (var i = 0; i < nodes.length; i++) {
25
+ if (nodes[i].checked && nodes[i].form === form) {
26
+ return nodes[i];
27
+ }
28
+ }
29
+ }
30
+
31
+ function isNotRadioOrTabbableRadio(node: any) {
32
+ if (node.tagName !== 'INPUT' || node.type !== 'radio' || !node.name) {
33
+ return true;
34
+ }
35
+ var radioScope = node.form || node.ownerDocument;
36
+ var radioSet = radioScope.querySelectorAll(
37
+ 'input[type="radio"][name="' + node.name + '"]'
38
+ );
39
+ var checked = getCheckedRadio(radioSet, node.form);
40
+ return checked === node || (checked === undefined && radioSet[0] === node);
41
+ }
42
+
23
43
  export function getAllTabbingElements(parentElem: any) {
44
+ var currentActiveElement = document.activeElement;
24
45
  var tabbableNodes = parentElem.querySelectorAll(candidateSelectors.join(','));
25
46
  var onlyTabbable = [];
26
47
  for (var i = 0; i < tabbableNodes.length; i++) {
27
48
  var node = tabbableNodes[i];
28
- if (!node.disabled && getTabindex(node) > -1 && !isHidden(node)) {
49
+ if (
50
+ currentActiveElement === node ||
51
+ (!node.disabled &&
52
+ getTabindex(node) > -1 &&
53
+ !isHidden(node) &&
54
+ isNotRadioOrTabbableRadio(node))
55
+ ) {
29
56
  onlyTabbable.push(node);
30
57
  }
31
58
  }
@@ -1,37 +1,40 @@
1
- const modals: { element: HTMLDivElement; blockScroll: boolean }[] = [];
1
+ import { Ref, useEffect } from 'react';
2
+
3
+ let modals: Ref<Element>[] = [];
2
4
 
3
5
  /**
4
6
  * Handle the order of the modals.
5
7
  * Inspired by the material-ui implementation.
6
8
  */
7
- export default {
8
- /**
9
- * Return the modals array
10
- */
11
- modals: () => modals,
12
-
9
+ export const modalManager = {
13
10
  /**
14
11
  * Register a new modal
15
12
  */
16
- add: (newModal: HTMLDivElement, blockScroll: boolean) => {
17
- if (modals.findIndex((modal) => modal.element === newModal) === -1) {
18
- modals.push({ element: newModal, blockScroll });
19
- }
13
+ add: (newModal: Ref<Element>) => {
14
+ modals.push(newModal);
20
15
  },
21
16
 
22
17
  /**
23
18
  * Remove a modal
24
19
  */
25
- remove: (oldModal: HTMLDivElement) => {
26
- const index = modals.findIndex((modal) => modal.element === oldModal);
27
- if (index !== -1) {
28
- modals.splice(index, 1);
29
- }
20
+ remove: (oldModal: Ref<Element>) => {
21
+ modals = modals.filter((modal) => modal !== oldModal);
30
22
  },
31
23
 
32
24
  /**
33
- * Check if the modal is the first one on the screen
25
+ * When multiple modals are rendered will return true if current modal is the last one
34
26
  */
35
- isTopModal: (modal: HTMLDivElement) =>
36
- !!modals.length && modals[modals.length - 1]?.element === modal,
27
+ isTopModal: (modal: Ref<Element>) =>
28
+ !!modals.length && modals[modals.length - 1] === modal,
37
29
  };
30
+
31
+ export function useModalManager(ref: Ref<Element>, open: boolean) {
32
+ useEffect(() => {
33
+ if (open) {
34
+ modalManager.add(ref);
35
+ }
36
+ return () => {
37
+ modalManager.remove(ref);
38
+ };
39
+ }, [open, ref]);
40
+ }
@@ -0,0 +1,25 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock';
3
+
4
+ export const useScrollLock = (
5
+ refModal: React.RefObject<Element>,
6
+ open: boolean,
7
+ showPortal: boolean,
8
+ blockScroll: boolean,
9
+ reserveScrollBarGap?: boolean
10
+ ) => {
11
+ const oldRef = useRef<Element | null>(null);
12
+
13
+ useEffect(() => {
14
+ if (open && refModal.current && blockScroll) {
15
+ oldRef.current = refModal.current;
16
+ disableBodyScroll(refModal.current, { reserveScrollBarGap });
17
+ }
18
+ return () => {
19
+ if (oldRef.current) {
20
+ enableBodyScroll(oldRef.current);
21
+ oldRef.current = null;
22
+ }
23
+ };
24
+ }, [open, showPortal, refModal, blockScroll, reserveScrollBarGap]);
25
+ };
package/src/utils.ts CHANGED
@@ -1,17 +1 @@
1
- import noScroll from 'no-scroll';
2
- import modalManager from './modalManager';
3
-
4
1
  export const isBrowser = typeof window !== 'undefined';
5
-
6
- export const blockNoScroll = () => {
7
- noScroll.on();
8
- };
9
-
10
- export const unblockNoScroll = () => {
11
- // Restore the scroll only if there is no modal on the screen
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) {
15
- noScroll.off();
16
- }
17
- };
package/styles.css CHANGED
@@ -1,30 +1,50 @@
1
- .react-responsive-modal-overlay {
2
- background: rgba(0, 0, 0, 0.75);
3
- display: flex;
4
- align-items: flex-start;
1
+ .react-responsive-modal-root {
5
2
  position: fixed;
6
3
  top: 0;
4
+ bottom: 0;
7
5
  left: 0;
8
6
  right: 0;
7
+ z-index: 1000;
8
+ }
9
+
10
+ .react-responsive-modal-overlay {
11
+ background: rgba(0, 0, 0, 0.5);
12
+ position: fixed;
13
+ top: 0;
9
14
  bottom: 0;
10
- overflow-y: auto;
15
+ left: 0;
16
+ right: 0;
17
+ z-index: -1;
18
+ }
19
+
20
+ .react-responsive-modal-container {
21
+ height: 100%;
22
+ outline: 0;
11
23
  overflow-x: hidden;
12
- z-index: 1000;
13
- padding: 1.2rem;
24
+ overflow-y: auto;
25
+ text-align: center;
26
+ }
27
+
28
+ /* Used to trick the browser to center the modal content properly */
29
+ .react-responsive-modal-containerCenter:after {
30
+ width: 0;
31
+ height: 100%;
32
+ content: '';
33
+ display: inline-block;
34
+ vertical-align: middle;
14
35
  }
15
36
 
16
37
  .react-responsive-modal-modal {
17
38
  max-width: 800px;
18
- position: relative;
19
- padding: 1.2rem;
39
+ display: inline-block;
40
+ text-align: left;
41
+ vertical-align: middle;
20
42
  background: #ffffff;
21
- background-clip: padding-box;
22
43
  box-shadow: 0 12px 15px 0 rgba(0, 0, 0, 0.25);
23
- margin: 0 auto;
24
- }
25
-
26
- .react-responsive-modal-modalCenter {
27
- margin: auto;
44
+ margin: 1.2rem;
45
+ padding: 1.2rem;
46
+ position: relative;
47
+ overflow-y: auto;
28
48
  }
29
49
 
30
50
  .react-responsive-modal-closeButton {
@@ -38,20 +58,42 @@
38
58
  display: flex;
39
59
  }
40
60
 
41
- @keyframes react-responsive-modal-fadeIn {
61
+ @keyframes react-responsive-modal-overlay-in {
62
+ 0% {
63
+ opacity: 0;
64
+ }
65
+ 100% {
66
+ opacity: 1;
67
+ }
68
+ }
69
+
70
+ @keyframes react-responsive-modal-overlay-out {
71
+ 0% {
72
+ opacity: 1;
73
+ }
74
+ 100% {
75
+ opacity: 0;
76
+ }
77
+ }
78
+
79
+ @keyframes react-responsive-modal-modal-in {
42
80
  0% {
81
+ transform: scale(0.96);
43
82
  opacity: 0;
44
83
  }
45
84
  100% {
85
+ transform: scale(100%);
46
86
  opacity: 1;
47
87
  }
48
88
  }
49
89
 
50
- @keyframes react-responsive-modal-fadeOut {
90
+ @keyframes react-responsive-modal-modal-out {
51
91
  0% {
92
+ transform: scale(100%);
52
93
  opacity: 1;
53
94
  }
54
95
  100% {
96
+ transform: scale(0.96);
55
97
  opacity: 0;
56
98
  }
57
99
  }
package/CHANGELOG.md DELETED
@@ -1,41 +0,0 @@
1
- # Changelog
2
-
3
- ### [5.2.6](https://www.github.com/pradel/react-responsive-modal/compare/v5.2.5...v5.2.6) (2020-11-07)
4
-
5
-
6
- ### Miscellaneous
7
-
8
- * fix publishing ([f024bd5](https://www.github.com/pradel/react-responsive-modal/commit/f024bd588ff315f440cc090eb90595d6f165fb98))
9
-
10
- ### [5.2.5](https://www.github.com/pradel/react-responsive-modal/compare/v5.2.4...v5.2.5) (2020-11-07)
11
-
12
-
13
- ### Miscellaneous
14
-
15
- * fix build ([1a5f07c](https://www.github.com/pradel/react-responsive-modal/commit/1a5f07cb7a6f6682c01d487129309152e41b23c0))
16
-
17
- ### [5.2.4](https://www.github.com/pradel/react-responsive-modal/compare/v5.2.3...v5.2.4) (2020-11-07)
18
-
19
-
20
- ### Miscellaneous
21
-
22
- * trigger release ([d14af23](https://www.github.com/pradel/react-responsive-modal/commit/d14af2334292d9aaf81385ccfdcd0b7ff506a7cb))
23
-
24
- ### [5.2.3](https://www.github.com/pradel/react-responsive-modal/compare/v5.2.2...v5.2.3) (2020-11-07)
25
-
26
-
27
- ### Miscellaneous
28
-
29
- * upgrade dev dependencies ([6745a09](https://www.github.com/pradel/react-responsive-modal/commit/6745a09ddd26ac938f77615afc7ced8ff1703e62))
30
-
31
- ### [5.2.2](https://www.github.com/pradel/react-responsive-modal/compare/v5.2.1...v5.2.2) (2020-11-07)
32
-
33
-
34
- ### Bug Fixes
35
-
36
- * fix closing modal via close icon ([#437](https://www.github.com/pradel/react-responsive-modal/issues/437)) ([f13ee4a](https://www.github.com/pradel/react-responsive-modal/commit/f13ee4abfce63b156f64a8cf5ea5ea50dfff4e19))
37
-
38
-
39
- ### Tests
40
-
41
- * add tests for body scroll blocking ([#438](https://www.github.com/pradel/react-responsive-modal/issues/438)) ([f4077b8](https://www.github.com/pradel/react-responsive-modal/commit/f4077b8f0f24d9e4b12107d8ebe7382d5dafbfef))
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 Léo Pradel
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.