react-responsive-modal 6.4.2 → 7.0.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.
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "react-responsive-modal",
3
- "version": "6.4.2",
3
+ "version": "7.0.0",
4
4
  "description": "A simple responsive and accessible react modal",
5
5
  "license": "MIT",
6
- "main": "dist/index.js",
7
- "module": "dist/react-responsive-modal.esm.js",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
8
9
  "typings": "dist/index.d.ts",
9
10
  "scripts": {
10
- "start": "tsdx watch",
11
- "build": "tsdx build",
12
- "test": "tsdx test --passWithNoTests",
13
- "lint": "tsdx lint",
14
- "prepare": "tsdx build",
11
+ "start": "tsdown --watch",
12
+ "build": "tsdown",
13
+ "typecheck": "tsc --noEmit",
14
+ "test": "vitest",
15
+ "prepare": "tsdown",
15
16
  "size": "size-limit"
16
17
  },
17
18
  "files": [
@@ -19,17 +20,6 @@
19
20
  "src",
20
21
  "styles.css"
21
22
  ],
22
- "jest": {
23
- "setupFilesAfterEnv": [
24
- "./__tests__/setupTests.ts"
25
- ],
26
- "modulePathIgnorePatterns": [
27
- "cypress"
28
- ],
29
- "coveragePathIgnorePatterns": [
30
- "src/lib"
31
- ]
32
- },
33
23
  "keywords": [
34
24
  "react",
35
25
  "responsive",
@@ -37,7 +27,11 @@
37
27
  "mobile",
38
28
  "flex"
39
29
  ],
40
- "repository": "git+https://github.com/pradel/react-responsive-modal.git",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/pradel/react-responsive-modal.git",
33
+ "directory": "react-responsive-modal"
34
+ },
41
35
  "author": "Léo Pradel",
42
36
  "bugs": {
43
37
  "url": "https://github.com/pradel/react-responsive-modal/issues"
@@ -46,41 +40,54 @@
46
40
  "funding": "https://github.com/sponsors/pradel",
47
41
  "size-limit": [
48
42
  {
49
- "path": "dist/react-responsive-modal.cjs.production.min.js",
50
- "limit": "4.1 KB"
43
+ "path": "dist/index.js",
44
+ "limit": "3.6 KB"
51
45
  },
52
46
  {
53
- "path": "dist/react-responsive-modal.esm.js",
54
- "limit": "4.1 KB"
47
+ "path": "dist/index.cjs",
48
+ "limit": "4.0 KB"
55
49
  }
56
50
  ],
57
51
  "dependencies": {
58
- "@bedrock-layout/use-forwarded-ref": "^1.3.1",
52
+ "@bedrock-layout/use-forwarded-ref": "^2.0.17",
59
53
  "body-scroll-lock": "^3.1.5",
60
54
  "classnames": "^2.3.1"
61
55
  },
62
56
  "peerDependencies": {
63
- "react": "^16.8.0 || ^17 || ^18",
64
- "react-dom": "^16.8.0 || ^17 || ^18"
57
+ "react": "^16.8.0 || ^17 || ^18 || ^19",
58
+ "react-dom": "^16.8.0 || ^17 || ^18 || ^19"
65
59
  },
66
60
  "devDependencies": {
67
- "@size-limit/preset-small-lib": "4.7.0",
68
- "@testing-library/jest-dom": "5.11.6",
69
- "@testing-library/react": "11.1.2",
70
- "@types/body-scroll-lock": "2.6.1",
71
- "@types/classnames": "2.2.11",
72
- "@types/node": "14.14.7",
73
- "@types/react": "16.9.56",
74
- "@types/react-dom": "16.9.9",
75
- "babel-jest": "26.6.3",
76
- "cypress": "5.6.0",
77
- "husky": "4.3.0",
78
- "prettier": "2.1.2",
79
- "react": "17.0.1",
80
- "react-dom": "17.0.1",
81
- "size-limit": "4.7.0",
82
- "tsdx": "0.14.1",
83
- "tslib": "2.0.3",
84
- "typescript": "4.0.5"
61
+ "@codecov/vite-plugin": "1.9.1",
62
+ "@size-limit/preset-small-lib": "11.2.0",
63
+ "@testing-library/dom": "10.4.0",
64
+ "@testing-library/jest-dom": "6.6.3",
65
+ "@testing-library/react": "16.3.0",
66
+ "@types/body-scroll-lock": "2.6.2",
67
+ "@types/classnames": "2.3.4",
68
+ "@types/node": "22.16.3",
69
+ "@types/react": "19.1.8",
70
+ "@types/react-dom": "19.1.6",
71
+ "@vitejs/plugin-react": "4.6.0",
72
+ "@vitest/coverage-istanbul": "3.2.4",
73
+ "cypress": "14.5.1",
74
+ "jsdom": "26.1.0",
75
+ "publint": "0.3.12",
76
+ "react": "19.1.0",
77
+ "react-dom": "19.1.0",
78
+ "size-limit": "11.2.0",
79
+ "tsdown": "0.12.9",
80
+ "tslib": "2.8.1",
81
+ "typescript": "5.8.3",
82
+ "vitest": "3.2.4"
83
+ },
84
+ "types": "./dist/index.d.cts",
85
+ "exports": {
86
+ ".": {
87
+ "import": "./dist/index.js",
88
+ "require": "./dist/index.cjs"
89
+ },
90
+ "./package.json": "./package.json",
91
+ "./styles.css": "./styles.css"
85
92
  }
86
93
  }
package/src/FocusTrap.tsx CHANGED
@@ -8,11 +8,11 @@ import {
8
8
 
9
9
  interface FocusTrapProps {
10
10
  container?: React.RefObject<HTMLElement> | null;
11
- initialFocusRef?: React.RefObject<HTMLElement>;
11
+ initialFocusRef?: React.RefObject<HTMLElement | null>;
12
12
  }
13
13
 
14
14
  export const FocusTrap = ({ container, initialFocusRef }: FocusTrapProps) => {
15
- const refLastFocus = useRef<HTMLElement | null>();
15
+ const refLastFocus = useRef<HTMLElement | null>(null);
16
16
  /**
17
17
  * Handle focus lock on the modal
18
18
  */
@@ -33,7 +33,7 @@ export const FocusTrap = ({ container, initialFocusRef }: FocusTrapProps) => {
33
33
  // only if it's a focusable element
34
34
  if (
35
35
  candidateSelectors.findIndex((selector) =>
36
- document.activeElement?.matches(selector)
36
+ document.activeElement?.matches(selector),
37
37
  ) !== -1
38
38
  ) {
39
39
  refLastFocus.current = document.activeElement as HTMLElement;
package/src/index.tsx CHANGED
@@ -1,12 +1,12 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
- import ReactDom from 'react-dom';
2
+ import { createPortal } from 'react-dom';
3
3
  import cx from 'classnames';
4
+ import { useForwardedRef } from '@bedrock-layout/use-forwarded-ref';
4
5
  import CloseIcon from './CloseIcon';
5
6
  import { FocusTrap } from './FocusTrap';
6
7
  import { modalManager, useModalManager } from './modalManager';
7
8
  import { useScrollLock } from './useScrollLock';
8
9
  import { isBrowser } from './utils';
9
- import useForwardedRef from '@bedrock-layout/use-forwarded-ref';
10
10
 
11
11
  const classes = {
12
12
  root: 'react-responsive-modal-root',
@@ -75,7 +75,7 @@ export interface ModalProps {
75
75
  *
76
76
  * Default to undefined.
77
77
  */
78
- initialFocusRef?: React.RefObject<HTMLElement>;
78
+ initialFocusRef?: React.RefObject<HTMLElement | null>;
79
79
  /**
80
80
  * You can specify a container prop which should be of type `Element`.
81
81
  * The portal will be rendered inside that element.
@@ -152,7 +152,7 @@ export interface ModalProps {
152
152
  * Callback fired when the overlay is clicked.
153
153
  */
154
154
  onOverlayClick?: (
155
- event: React.MouseEvent<HTMLDivElement, MouseEvent>
155
+ event: React.MouseEvent<HTMLDivElement, MouseEvent>,
156
156
  ) => void;
157
157
  /**
158
158
  * Callback fired when the Modal has exited and the animation is finished.
@@ -190,7 +190,7 @@ export const Modal = React.forwardRef(
190
190
  children,
191
191
  reserveScrollBarGap,
192
192
  }: ModalProps,
193
- ref: React.ForwardedRef<HTMLDivElement>
193
+ ref: React.ForwardedRef<HTMLDivElement>,
194
194
  ) => {
195
195
  const refDialog = useForwardedRef(ref);
196
196
  const refModal = useRef<HTMLDivElement>(null);
@@ -267,7 +267,7 @@ export const Modal = React.forwardRef(
267
267
  }, [open]);
268
268
 
269
269
  const handleClickOverlay = (
270
- event: React.MouseEvent<HTMLDivElement, MouseEvent>
270
+ event: React.MouseEvent<HTMLDivElement, MouseEvent>,
271
271
  ) => {
272
272
  if (refShouldClose.current === null) {
273
273
  refShouldClose.current = true;
@@ -302,15 +302,15 @@ export const Modal = React.forwardRef(
302
302
  const containerModal = container || refContainer.current;
303
303
 
304
304
  const overlayAnimation = open
305
- ? classNames?.overlayAnimationIn ?? classes.overlayAnimationIn
306
- : classNames?.overlayAnimationOut ?? classes.overlayAnimationOut;
305
+ ? (classNames?.overlayAnimationIn ?? classes.overlayAnimationIn)
306
+ : (classNames?.overlayAnimationOut ?? classes.overlayAnimationOut);
307
307
 
308
308
  const modalAnimation = open
309
- ? classNames?.modalAnimationIn ?? classes.modalAnimationIn
310
- : classNames?.modalAnimationOut ?? classes.modalAnimationOut;
309
+ ? (classNames?.modalAnimationIn ?? classes.modalAnimationIn)
310
+ : (classNames?.modalAnimationOut ?? classes.modalAnimationOut);
311
311
 
312
312
  return showPortal && containerModal
313
- ? ReactDom.createPortal(
313
+ ? createPortal(
314
314
  <div
315
315
  className={cx(classes.root, classNames?.root)}
316
316
  style={styles?.root}
@@ -331,7 +331,7 @@ export const Modal = React.forwardRef(
331
331
  className={cx(
332
332
  classes.modalContainer,
333
333
  center && classes.modalContainerCenter,
334
- classNames?.modalContainer
334
+ classNames?.modalContainer,
335
335
  )}
336
336
  style={styles?.modalContainer}
337
337
  data-testid="modal-container"
@@ -376,10 +376,10 @@ export const Modal = React.forwardRef(
376
376
  </div>
377
377
  </div>
378
378
  </div>,
379
- containerModal
379
+ containerModal,
380
380
  )
381
381
  : null;
382
- }
382
+ },
383
383
  );
384
384
 
385
385
  export default Modal;
@@ -34,7 +34,7 @@ function isNotRadioOrTabbableRadio(node: any) {
34
34
  }
35
35
  var radioScope = node.form || node.ownerDocument;
36
36
  var radioSet = radioScope.querySelectorAll(
37
- 'input[type="radio"][name="' + node.name + '"]'
37
+ 'input[type="radio"][name="' + node.name + '"]',
38
38
  );
39
39
  var checked = getCheckedRadio(radioSet, node.form);
40
40
  return checked === node || (checked === undefined && radioSet[0] === node);
@@ -2,11 +2,11 @@ import { useEffect, useRef } from 'react';
2
2
  import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock';
3
3
 
4
4
  export const useScrollLock = (
5
- refModal: React.RefObject<Element>,
5
+ refModal: React.RefObject<Element | null>,
6
6
  open: boolean,
7
7
  showPortal: boolean,
8
8
  blockScroll: boolean,
9
- reserveScrollBarGap?: boolean
9
+ reserveScrollBarGap?: boolean,
10
10
  ) => {
11
11
  const oldRef = useRef<Element | null>(null);
12
12
 
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- interface CloseIconProps {
3
- id?: string;
4
- closeIcon?: React.ReactNode;
5
- styles?: {
6
- closeButton?: React.CSSProperties;
7
- closeIcon?: React.CSSProperties;
8
- };
9
- classNames?: {
10
- closeButton?: string;
11
- closeIcon?: string;
12
- };
13
- classes: {
14
- closeButton?: string;
15
- };
16
- onClick: () => void;
17
- }
18
- declare const CloseIcon: ({ classes, classNames, styles, id, closeIcon, onClick, }: CloseIconProps) => JSX.Element;
19
- export default CloseIcon;
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- interface FocusTrapProps {
3
- container?: React.RefObject<HTMLElement> | null;
4
- initialFocusRef?: React.RefObject<HTMLElement>;
5
- }
6
- export declare const FocusTrap: ({ container, initialFocusRef }: FocusTrapProps) => null;
7
- export {};
@@ -1,3 +0,0 @@
1
- export declare const candidateSelectors: string[];
2
- export declare function getAllTabbingElements(parentElem: any): any[];
3
- export declare function tabTrappingKey(event: any, parentElem: any): boolean | undefined;
@@ -1,20 +0,0 @@
1
- import { Ref } from 'react';
2
- /**
3
- * Handle the order of the modals.
4
- * Inspired by the material-ui implementation.
5
- */
6
- export declare const modalManager: {
7
- /**
8
- * Register a new modal
9
- */
10
- add: (newModal: Ref<Element>) => void;
11
- /**
12
- * Remove a modal
13
- */
14
- remove: (oldModal: Ref<Element>) => void;
15
- /**
16
- * When multiple modals are rendered will return true if current modal is the last one
17
- */
18
- isTopModal: (modal: Ref<Element>) => boolean;
19
- };
20
- export declare function useModalManager(ref: Ref<Element>, open: boolean): void;