focus-trap-react 10.3.0 → 11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 11.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 4a37dae: Dropping `propTypes` and `defaultProps` no longer supported by React 19 and long deprecated in React 18 (going forward, use TypeScript for prop typings, and if necessary, a runtime library to validate props); Increasing minimum supported React version up to >=18; Bumping `focus-trap` dependency to v7.6.2
8
+
9
+ ## 10.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - ee62d91: Bump focus-trap to v7.6.1
14
+
3
15
  ## 10.3.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -33,14 +33,23 @@ npm install focus-trap-react
33
33
 
34
34
  ### React dependency
35
35
 
36
- React `>= 16.3.0`
36
+ React `>= 18.0.0`
37
37
 
38
- ## Browser Support
38
+ > Note that while React 18.x still supported `propTypes` and `defaultProps`, they had long-since been deprecated, and are completely dropped in React 19.
39
+
40
+ Therefore, this library no longer assigns these properties to the `<FocusTrap>` element for runtime validation and initialization. The same techniques you would now use in React 19 are backward-compatible with React 18:
41
+
42
+ - Use TypeScript for static prop type validation
43
+ - Use a runtime validation library such as [RTV.js](https://rtvjs.stefcameron.com/), [JSON Schema](https://json-schema.org/), or [yup](https://github.com/jquense/yup) for runtime prop validation to replace `prop-types`)
39
44
 
40
- As old and as broad as _reasonably_ possible, excluding browsers that are out of support or have nearly no user base.
45
+ > This library aims to support one major version of React _behind_ the current major version, since React major releases are typically years apart -- to the extent that the feature drift is not too great and remains reasonably surmountable.
46
+
47
+ ## Browser Support
41
48
 
42
49
  Focused on desktop browsers, particularly Chrome, Edge, FireFox, Safari, and Opera.
43
50
 
51
+ Gated by what React [supports](https://legacy.reactjs.org/docs/javascript-environment-requirements.html) in the version [currently](#react-dependency) supported.
52
+
44
53
  Focus-trap-react is not officially tested on any mobile browsers or devices.
45
54
 
46
55
  > ⚠️ Microsoft [no longer supports](https://blogs.windows.com/windowsexperience/2022/06/15/internet-explorer-11-has-retired-and-is-officially-out-of-support-what-you-need-to-know/) any version of IE, so IE is no longer supported by this library.
@@ -15,11 +15,14 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
15
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
16
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
17
  var React = require('react');
18
- var PropTypes = require('prop-types');
19
18
  var _require = require('focus-trap'),
20
19
  createFocusTrap = _require.createFocusTrap;
21
20
  var _require2 = require('tabbable'),
22
21
  isFocusable = _require2.isFocusable;
22
+
23
+ /**
24
+ * @type {import('../index.d.ts').FocusTrap}
25
+ */
23
26
  var FocusTrap = /*#__PURE__*/function (_React$Component) {
24
27
  function FocusTrap(props) {
25
28
  var _this;
@@ -386,52 +389,10 @@ var FocusTrap = /*#__PURE__*/function (_React$Component) {
386
389
  return null;
387
390
  }
388
391
  }]);
389
- }(React.Component); // support server-side rendering where `Element` will not be defined
390
- var ElementType = typeof Element === 'undefined' ? Function : Element;
391
- FocusTrap.propTypes = {
392
- active: PropTypes.bool,
393
- paused: PropTypes.bool,
394
- focusTrapOptions: PropTypes.shape({
395
- document: PropTypes.object,
396
- onActivate: PropTypes.func,
397
- onPostActivate: PropTypes.func,
398
- checkCanFocusTrap: PropTypes.func,
399
- onPause: PropTypes.func,
400
- onPostPause: PropTypes.func,
401
- onUnpause: PropTypes.func,
402
- onPostUnpause: PropTypes.func,
403
- onDeactivate: PropTypes.func,
404
- onPostDeactivate: PropTypes.func,
405
- checkCanReturnFocus: PropTypes.func,
406
- initialFocus: PropTypes.oneOfType([PropTypes.instanceOf(ElementType), PropTypes.string, PropTypes.bool, PropTypes.func]),
407
- fallbackFocus: PropTypes.oneOfType([PropTypes.instanceOf(ElementType), PropTypes.string,
408
- // NOTE: does not support `false` as value (or return value from function)
409
- PropTypes.func]),
410
- escapeDeactivates: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
411
- clickOutsideDeactivates: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
412
- returnFocusOnDeactivate: PropTypes.bool,
413
- setReturnFocus: PropTypes.oneOfType([PropTypes.instanceOf(ElementType), PropTypes.string, PropTypes.bool, PropTypes.func]),
414
- allowOutsideClick: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
415
- preventScroll: PropTypes.bool,
416
- tabbableOptions: PropTypes.shape({
417
- displayCheck: PropTypes.oneOf(['full', 'legacy-full', 'non-zero-area', 'none']),
418
- getShadowRoot: PropTypes.oneOfType([PropTypes.bool, PropTypes.func])
419
- }),
420
- trapStack: PropTypes.array,
421
- isKeyForward: PropTypes.func,
422
- isKeyBackward: PropTypes.func
423
- }),
424
- containerElements: PropTypes.arrayOf(PropTypes.instanceOf(ElementType)),
425
- // DOM element ONLY
426
- children: PropTypes.oneOfType([PropTypes.element,
427
- // React element
428
- PropTypes.instanceOf(ElementType) // DOM element
429
- ])
430
-
431
- // NOTE: _createFocusTrap is internal, for testing purposes only, so we don't
432
- // specify it here. It's expected to be set to the function returned from
433
- // require('focus-trap'), or one with a compatible interface.
434
- };
392
+ }(React.Component); // NOTE: While React 19 REMOVED support for `propTypes`, support for `defaultProps`
393
+ // __for class components ONLY__ remains: "Class components will continue to support
394
+ // defaultProps since there is no ES6 alternative."
395
+ // @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-proptypes-and-defaultprops
435
396
  FocusTrap.defaultProps = {
436
397
  active: true,
437
398
  paused: false,
package/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Options as FocusTrapOptions } from 'focus-trap';
2
2
  import * as React from 'react';
3
3
 
4
- export = FocusTrap;
5
-
6
4
  declare namespace FocusTrap {
7
5
  export interface Props extends React.AllHTMLAttributes<any> {
8
6
  children?: React.ReactNode;
@@ -13,4 +11,4 @@ declare namespace FocusTrap {
13
11
  }
14
12
  }
15
13
 
16
- declare class FocusTrap extends React.Component<FocusTrap.Props> { }
14
+ export declare class FocusTrap extends React.Component<FocusTrap.Props> { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "focus-trap-react",
3
- "version": "10.3.0",
3
+ "version": "11.0.0",
4
4
  "description": "A React component that traps focus.",
5
5
  "main": "dist/focus-trap-react.js",
6
6
  "types": "index.d.ts",
@@ -57,50 +57,52 @@
57
57
  },
58
58
  "homepage": "https://github.com/focus-trap/focus-trap-react#readme",
59
59
  "devDependencies": {
60
- "@babel/cli": "^7.25.6",
61
- "@babel/core": "^7.25.2",
62
- "@babel/eslint-parser": "^7.25.1",
60
+ "@babel/cli": "^7.25.9",
61
+ "@babel/core": "^7.26.0",
62
+ "@babel/eslint-parser": "^7.25.9",
63
63
  "@babel/plugin-proposal-class-properties": "^7.18.6",
64
- "@babel/preset-env": "^7.25.4",
65
- "@babel/preset-react": "^7.24.7",
66
- "@changesets/cli": "^2.27.8",
64
+ "@babel/preset-env": "^7.26.0",
65
+ "@babel/preset-react": "^7.25.9",
66
+ "@changesets/cli": "^2.27.10",
67
67
  "@testing-library/cypress": "^10.0.2",
68
68
  "@testing-library/dom": "^10.4.0",
69
- "@testing-library/jest-dom": "^6.5.0",
70
- "@testing-library/react": "^16.0.1",
69
+ "@testing-library/jest-dom": "^6.6.3",
70
+ "@testing-library/react": "^16.1.0",
71
71
  "@testing-library/user-event": "^14.5.2",
72
- "@types/jquery": "^3.5.30",
72
+ "@types/jquery": "^3.5.32",
73
+ "@types/react": "^18.3.1",
74
+ "@types/react-dom": "^18.3.0",
73
75
  "all-contributors-cli": "^6.26.1",
74
76
  "babel-jest": "^29.7.0",
75
77
  "babelify": "^10.0.0",
76
- "browserify": "^17.0.0",
78
+ "browserify": "^17.0.1",
77
79
  "budo": "^11.8.4",
78
- "cypress": "^13.14.2",
80
+ "cypress": "^13.16.0",
79
81
  "cypress-plugin-tab": "^1.0.5",
80
82
  "eslint": "^8.57.0",
81
83
  "eslint-config-prettier": "^9.1.0",
82
- "eslint-plugin-cypress": "^3.5.0",
83
- "eslint-plugin-jest": "^28.8.3",
84
- "eslint-plugin-react": "^7.36.1",
84
+ "eslint-plugin-cypress": "^3.6.0",
85
+ "eslint-plugin-jest": "^28.9.0",
86
+ "eslint-plugin-react": "^7.37.2",
85
87
  "jest": "^29.7.0",
86
88
  "jest-environment-jsdom": "^29.7.0",
87
89
  "jest-watch-typeahead": "^2.2.2",
88
90
  "onchange": "^7.1.0",
89
- "prettier": "^3.3.3",
90
- "prop-types": "^15.8.1",
91
+ "prettier": "^3.4.1",
91
92
  "react": "^18.3.1",
92
93
  "react-dom": "^18.3.1",
93
94
  "regenerator-runtime": "^0.14.1",
94
95
  "start-server-and-test": "^2.0.8",
95
- "typescript": "^5.6.2"
96
+ "typescript": "^5.7.2"
96
97
  },
97
98
  "dependencies": {
98
- "focus-trap": "^7.6.0",
99
+ "focus-trap": "^7.6.2",
99
100
  "tabbable": "^6.2.0"
100
101
  },
101
102
  "peerDependencies": {
102
- "prop-types": "^15.8.1",
103
- "react": ">=16.3.0",
104
- "react-dom": ">=16.3.0"
103
+ "@types/react": "^18.0.0 || ^19.0.0",
104
+ "@types/react-dom": "^18.0.0 || ^19.0.0",
105
+ "react": "^18.0.0 || ^19.0.0",
106
+ "react-dom": "^18.0.0 || ^19.0.0"
105
107
  }
106
108
  }
@@ -1,8 +1,10 @@
1
1
  const React = require('react');
2
- const PropTypes = require('prop-types');
3
2
  const { createFocusTrap } = require('focus-trap');
4
3
  const { isFocusable } = require('tabbable');
5
4
 
5
+ /**
6
+ * @type {import('../index.d.ts').FocusTrap}
7
+ */
6
8
  class FocusTrap extends React.Component {
7
9
  constructor(props) {
8
10
  super(props);
@@ -412,74 +414,10 @@ class FocusTrap extends React.Component {
412
414
  }
413
415
  }
414
416
 
415
- // support server-side rendering where `Element` will not be defined
416
- const ElementType = typeof Element === 'undefined' ? Function : Element;
417
-
418
- FocusTrap.propTypes = {
419
- active: PropTypes.bool,
420
- paused: PropTypes.bool,
421
- focusTrapOptions: PropTypes.shape({
422
- document: PropTypes.object,
423
- onActivate: PropTypes.func,
424
- onPostActivate: PropTypes.func,
425
- checkCanFocusTrap: PropTypes.func,
426
- onPause: PropTypes.func,
427
- onPostPause: PropTypes.func,
428
- onUnpause: PropTypes.func,
429
- onPostUnpause: PropTypes.func,
430
- onDeactivate: PropTypes.func,
431
- onPostDeactivate: PropTypes.func,
432
- checkCanReturnFocus: PropTypes.func,
433
- initialFocus: PropTypes.oneOfType([
434
- PropTypes.instanceOf(ElementType),
435
- PropTypes.string,
436
- PropTypes.bool,
437
- PropTypes.func,
438
- ]),
439
- fallbackFocus: PropTypes.oneOfType([
440
- PropTypes.instanceOf(ElementType),
441
- PropTypes.string,
442
- // NOTE: does not support `false` as value (or return value from function)
443
- PropTypes.func,
444
- ]),
445
- escapeDeactivates: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
446
- clickOutsideDeactivates: PropTypes.oneOfType([
447
- PropTypes.bool,
448
- PropTypes.func,
449
- ]),
450
- returnFocusOnDeactivate: PropTypes.bool,
451
- setReturnFocus: PropTypes.oneOfType([
452
- PropTypes.instanceOf(ElementType),
453
- PropTypes.string,
454
- PropTypes.bool,
455
- PropTypes.func,
456
- ]),
457
- allowOutsideClick: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
458
- preventScroll: PropTypes.bool,
459
- tabbableOptions: PropTypes.shape({
460
- displayCheck: PropTypes.oneOf([
461
- 'full',
462
- 'legacy-full',
463
- 'non-zero-area',
464
- 'none',
465
- ]),
466
- getShadowRoot: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
467
- }),
468
- trapStack: PropTypes.array,
469
- isKeyForward: PropTypes.func,
470
- isKeyBackward: PropTypes.func,
471
- }),
472
- containerElements: PropTypes.arrayOf(PropTypes.instanceOf(ElementType)), // DOM element ONLY
473
- children: PropTypes.oneOfType([
474
- PropTypes.element, // React element
475
- PropTypes.instanceOf(ElementType), // DOM element
476
- ]),
477
-
478
- // NOTE: _createFocusTrap is internal, for testing purposes only, so we don't
479
- // specify it here. It's expected to be set to the function returned from
480
- // require('focus-trap'), or one with a compatible interface.
481
- };
482
-
417
+ // NOTE: While React 19 REMOVED support for `propTypes`, support for `defaultProps`
418
+ // __for class components ONLY__ remains: "Class components will continue to support
419
+ // defaultProps since there is no ES6 alternative."
420
+ // @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-proptypes-and-defaultprops
483
421
  FocusTrap.defaultProps = {
484
422
  active: true,
485
423
  paused: false,