|
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, |
|
0 commit comments