focus-trap-react 11.0.0 → 11.0.1

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 11.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cd75caa: Fix missing default export in typings; props no longer extend `React.AllHTMLAttributes<any>` to allow things like `className` (those extra props have always been ignored anyway); deprecate default export; add named export in code ([#1396](https://github.com/focus-trap/focus-trap-react/issues/1396))
8
+
3
9
  ## 11.0.0
4
10
 
5
11
  ### Major Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # focus-trap-react [![CI](https://github.com/focus-trap/focus-trap-react/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/focus-trap/focus-trap-react/actions?query=workflow:CI+branch:master) [![Codecov](https://img.shields.io/codecov/c/github/focus-trap/focus-trap-react)](https://codecov.io/gh/focus-trap/focus-trap-react) [![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)
2
2
 
3
3
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4
- [![All Contributors](https://img.shields.io/badge/all_contributors-28-orange.svg?style=flat-square)](#contributors)
4
+ [![All Contributors](https://img.shields.io/badge/all_contributors-29-orange.svg?style=flat-square)](#contributors)
5
5
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
6
6
 
7
7
  A React component that traps focus.
@@ -84,10 +84,9 @@ You can read further code examples in `demo/` (it's very simple), and [see how i
84
84
  Here's one more simple example:
85
85
 
86
86
  ```jsx
87
- const React = require('react');
88
- const ReactDOM = require('react-dom'); // React 16-17
89
- const { createRoot } = require('react-dom/client'); // React 18
90
- const FocusTrap = require('focus-trap-react');
87
+ import React from 'react';
88
+ import { createRoot } from 'react-dom/client';
89
+ import { FocusTrap } from 'focus-trap-react';
91
90
 
92
91
  class Demo extends React.Component {
93
92
  constructor(props) {
@@ -150,7 +149,6 @@ class Demo extends React.Component {
150
149
  }
151
150
  }
152
151
 
153
- ReactDOM.render(<Demo />, document.getElementById('root')); // React 16-17
154
152
  createRoot(document.getElementById('root')).render(<Demo />); // React 18
155
153
  ```
156
154
 
@@ -192,14 +190,13 @@ The result can be that (depending on how you render the trap) in Strict Mode, th
192
190
  Example:
193
191
 
194
192
  ```jsx
195
- const React = require('react');
196
- const { createRoot } = require('react-dom/client');
197
- const propTypes = require('prop-types');
198
- const FocusTrap = require('../../dist/focus-trap-react');
193
+ import { forwardRef, Component } from 'react';
194
+ import { createRoot } from 'react-dom/client';
195
+ import { FocusTrap } from 'focus-trap-react';
199
196
 
200
197
  const container = document.getElementById('demo-function-child');
201
198
 
202
- const TrapChild = React.forwardRef(function ({ onDeactivate }, ref) {
199
+ const TrapChild = forwardRef(function ({ onDeactivate }, ref) {
203
200
  return (
204
201
  <div ref={ref}>
205
202
  <p>
@@ -223,7 +220,7 @@ TrapChild.propTypes = {
223
220
  onDeactivate: propTypes.func,
224
221
  };
225
222
 
226
- class DemoFunctionChild extends React.Component {
223
+ class DemoFunctionChild extends Component {
227
224
  constructor(props) {
228
225
  super(props);
229
226
 
@@ -359,21 +356,24 @@ In alphabetical order:
359
356
  <td align="center" valign="top" width="14.28%"><a href="https://marais.io/"><img src="https://avatars2.githubusercontent.com/u/599459?v=4?s=100" width="100px;" alt="Marais Rossouw"/><br /><sub><b>Marais Rossouw</b></sub></a><br /><a href="#infra-maraisr" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
360
357
  </tr>
361
358
  <tr>
359
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/Mathias-S"><img src="https://avatars.githubusercontent.com/u/225531?v=4?s=100" width="100px;" alt="Mathias Stang"/><br /><sub><b>Mathias Stang</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3AMathias-S" title="Bug reports">🐛</a> <a href="https://github.com/focus-trap/focus-trap-react/pulls?q=is%3Apr+reviewed-by%3AMathias-S" title="Reviewed Pull Requests">👀</a></td>
362
360
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/StackOverflowIsBetterThanAnyAI"><img src="https://avatars.githubusercontent.com/u/140268904?v=4?s=100" width="100px;" alt="Michael"/><br /><sub><b>Michael</b></sub></a><br /><a href="#example-StackOverflowIsBetterThanAnyAI" title="Examples">💡</a></td>
363
361
  <td align="center" valign="top" width="14.28%"><a href="https://www.moroshko.me"><img src="https://avatars.githubusercontent.com/u/259753?v=4?s=100" width="100px;" alt="Misha Moroshko"/><br /><sub><b>Misha Moroshko</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Amoroshko" title="Bug reports">🐛</a></td>
364
362
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/liunate"><img src="https://avatars2.githubusercontent.com/u/38996291?v=4?s=100" width="100px;" alt="Nate Liu"/><br /><sub><b>Nate Liu</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=liunate" title="Tests">⚠️</a></td>
365
363
  <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/rivajunior/"><img src="https://avatars1.githubusercontent.com/u/11370172?v=4?s=100" width="100px;" alt="Rivaldo Junior"/><br /><sub><b>Rivaldo Junior</b></sub></a><br /><a href="#maintenance-rivajunior" title="Maintenance">🚧</a></td>
366
364
  <td align="center" valign="top" width="14.28%"><a href="https://scottrippey.github.io/"><img src="https://avatars3.githubusercontent.com/u/430608?v=4?s=100" width="100px;" alt="Scott Rippey"/><br /><sub><b>Scott Rippey</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=scottrippey" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Ascottrippey" title="Bug reports">🐛</a></td>
367
365
  <td align="center" valign="top" width="14.28%"><a href="https://seanmcp.com/"><img src="https://avatars1.githubusercontent.com/u/6360367?v=4?s=100" width="100px;" alt="Sean McPherson"/><br /><sub><b>Sean McPherson</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=SeanMcP" title="Code">💻</a></td>
368
- <td align="center" valign="top" width="14.28%"><a href="http://smoores.dev"><img src="https://avatars.githubusercontent.com/u/5354254?v=4?s=100" width="100px;" alt="Shane Moore"/><br /><sub><b>Shane Moore</b></sub></a><br /><a href="#platform-SMores" title="Packaging/porting to new platform">📦</a></td>
369
366
  </tr>
370
367
  <tr>
368
+ <td align="center" valign="top" width="14.28%"><a href="http://smoores.dev"><img src="https://avatars.githubusercontent.com/u/5354254?v=4?s=100" width="100px;" alt="Shane Moore"/><br /><sub><b>Shane Moore</b></sub></a><br /><a href="#platform-SMores" title="Packaging/porting to new platform">📦</a></td>
371
369
  <td align="center" valign="top" width="14.28%"><a href="https://recollectr.io"><img src="https://avatars2.githubusercontent.com/u/6835891?v=4?s=100" width="100px;" alt="Slapbox"/><br /><sub><b>Slapbox</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=Slapbox" title="Documentation">📖</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3ASlapbox" title="Bug reports">🐛</a></td>
372
370
  <td align="center" valign="top" width="14.28%"><a href="https://stefancameron.com/"><img src="https://avatars3.githubusercontent.com/u/2855350?v=4?s=100" width="100px;" alt="Stefan Cameron"/><br /><sub><b>Stefan Cameron</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Astefcameron" title="Bug reports">🐛</a> <a href="#infra-stefcameron" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Tests">⚠️</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=stefcameron" title="Documentation">📖</a> <a href="#maintenance-stefcameron" title="Maintenance">🚧</a></td>
373
371
  <td align="center" valign="top" width="14.28%"><a href="http://tylerhawkins.info/201R/"><img src="https://avatars0.githubusercontent.com/u/13806458?v=4?s=100" width="100px;" alt="Tyler Hawkins"/><br /><sub><b>Tyler Hawkins</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=thawkin3" title="Documentation">📖</a> <a href="#example-thawkin3" title="Examples">💡</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=thawkin3" title="Tests">⚠️</a> <a href="#tool-thawkin3" title="Tools">🔧</a></td>
374
372
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/wandroll"><img src="https://avatars.githubusercontent.com/u/4492317?v=4?s=100" width="100px;" alt="Wandrille Verlut"/><br /><sub><b>Wandrille Verlut</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=wandroll" title="Code">💻</a> <a href="https://github.com/focus-trap/focus-trap-react/commits?author=wandroll" title="Tests">⚠️</a></td>
375
373
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/krikienoid"><img src="https://avatars3.githubusercontent.com/u/8528227?v=4?s=100" width="100px;" alt="krikienoid"/><br /><sub><b>krikienoid</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Akrikienoid" title="Bug reports">🐛</a></td>
376
374
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/robert-westenberger"><img src="https://avatars.githubusercontent.com/u/44252092?v=4?s=100" width="100px;" alt="robert-westenberger"/><br /><sub><b>robert-westenberger</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/commits?author=robert-westenberger" title="Documentation">📖</a> <a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Arobert-westenberger" title="Bug reports">🐛</a></td>
375
+ </tr>
376
+ <tr>
377
377
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/syntactic-salt"><img src="https://avatars.githubusercontent.com/u/9385662?v=4?s=100" width="100px;" alt="syntactic-salt"/><br /><sub><b>syntactic-salt</b></sub></a><br /><a href="https://github.com/focus-trap/focus-trap-react/issues?q=author%3Asyntactic-salt" title="Bug reports">🐛</a></td>
378
378
  </tr>
379
379
  </tbody>
@@ -399,4 +399,9 @@ FocusTrap.defaultProps = {
399
399
  focusTrapOptions: {},
400
400
  _createFocusTrap: createFocusTrap
401
401
  };
402
- module.exports = FocusTrap;
402
+
403
+ // 🔺 DEPRECATED: default export
404
+ module.exports = FocusTrap;
405
+
406
+ // named export
407
+ module.exports.FocusTrap = FocusTrap;
package/index.d.ts CHANGED
@@ -1,14 +1,56 @@
1
1
  import { Options as FocusTrapOptions } from 'focus-trap';
2
2
  import * as React from 'react';
3
3
 
4
+ export interface FocusTrapProps {
5
+ /**
6
+ * __Single container child__ for the trap. Use `containerElements` instead
7
+ * if you need a trap with multiple containers.
8
+ */
9
+ children?: React.ReactNode;
10
+
11
+ /**
12
+ * By default, the trap will be active when it mounts, so it's activated by
13
+ * mounting, and deactivated by unmounting. Use this prop to control when
14
+ * it's active while it's mounted, or if it's initially inactive.
15
+ */
16
+ active?: boolean;
17
+
18
+ /**
19
+ * To pause or unpause the trap while it's `active`. Primarily for use when
20
+ * you need to manage multiple traps in the same view. When paused, the trap
21
+ * retains its various event listeners, but ignores all events.
22
+ */
23
+ paused?: boolean;
24
+
25
+ /**
26
+ * See Focus-trap's [createOptions](https://github.com/focus-trap/focus-trap?tab=readme-ov-file#createoptions)
27
+ * for more details on available options.
28
+ */
29
+ focusTrapOptions?: FocusTrapOptions;
30
+
31
+ /**
32
+ * If specified, these elements will be used as the boundaries for the
33
+ * trap, __instead of the child__ specified in `children` (though
34
+ * `children` will still be rendered).
35
+ */
36
+ containerElements?: Array<HTMLElement>;
37
+ }
38
+
39
+ export declare class FocusTrap extends React.Component<FocusTrapProps> { }
40
+
41
+ /**
42
+ * Default export of the FocusTrap component.
43
+ * @deprecated 🔺 Use the named import `{ FocusTrap }` instead.
44
+ * @description 🔺 The default export will be removed in a future release. Migrate to the named
45
+ * import `{ FocusTrap }` today to ensure future compatibility.
46
+ */
4
47
  declare namespace FocusTrap {
5
- export interface Props extends React.AllHTMLAttributes<any> {
6
- children?: React.ReactNode;
7
- active?: boolean;
8
- paused?: boolean;
9
- focusTrapOptions?: FocusTrapOptions;
10
- containerElements?: Array<HTMLElement>;
11
- }
48
+ export type Props = FocusTrapProps;
12
49
  }
13
50
 
14
- export declare class FocusTrap extends React.Component<FocusTrap.Props> { }
51
+ /**
52
+ * @deprecated 🔺 Use the named import `{ FocusTrap }` instead.
53
+ * @description 🔺 The default export will be removed in a future release. Migrate to the named
54
+ * import `{ FocusTrap }` today to ensure future compatibility.
55
+ */
56
+ export default FocusTrap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "focus-trap-react",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "A React component that traps focus.",
5
5
  "main": "dist/focus-trap-react.js",
6
6
  "types": "index.d.ts",
@@ -57,12 +57,12 @@
57
57
  },
58
58
  "homepage": "https://github.com/focus-trap/focus-trap-react#readme",
59
59
  "devDependencies": {
60
- "@babel/cli": "^7.25.9",
60
+ "@babel/cli": "^7.26.4",
61
61
  "@babel/core": "^7.26.0",
62
62
  "@babel/eslint-parser": "^7.25.9",
63
63
  "@babel/plugin-proposal-class-properties": "^7.18.6",
64
64
  "@babel/preset-env": "^7.26.0",
65
- "@babel/preset-react": "^7.25.9",
65
+ "@babel/preset-react": "^7.26.3",
66
66
  "@changesets/cli": "^2.27.10",
67
67
  "@testing-library/cypress": "^10.0.2",
68
68
  "@testing-library/dom": "^10.4.0",
@@ -77,7 +77,7 @@
77
77
  "babelify": "^10.0.0",
78
78
  "browserify": "^17.0.1",
79
79
  "budo": "^11.8.4",
80
- "cypress": "^13.16.0",
80
+ "cypress": "^13.16.1",
81
81
  "cypress-plugin-tab": "^1.0.5",
82
82
  "eslint": "^8.57.0",
83
83
  "eslint-config-prettier": "^9.1.0",
@@ -88,11 +88,11 @@
88
88
  "jest-environment-jsdom": "^29.7.0",
89
89
  "jest-watch-typeahead": "^2.2.2",
90
90
  "onchange": "^7.1.0",
91
- "prettier": "^3.4.1",
91
+ "prettier": "^3.4.2",
92
92
  "react": "^18.3.1",
93
93
  "react-dom": "^18.3.1",
94
94
  "regenerator-runtime": "^0.14.1",
95
- "start-server-and-test": "^2.0.8",
95
+ "start-server-and-test": "^2.0.9",
96
96
  "typescript": "^5.7.2"
97
97
  },
98
98
  "dependencies": {
@@ -425,4 +425,8 @@ FocusTrap.defaultProps = {
425
425
  _createFocusTrap: createFocusTrap,
426
426
  };
427
427
 
428
+ // 🔺 DEPRECATED: default export
428
429
  module.exports = FocusTrap;
430
+
431
+ // named export
432
+ module.exports.FocusTrap = FocusTrap;