@mui/material 5.16.1 → 5.16.3
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/Autocomplete/Autocomplete.d.ts +6 -7
- package/Autocomplete/Autocomplete.js +1 -1
- package/Badge/Badge.d.ts +1 -1
- package/Badge/Badge.js +2 -2
- package/Badge/useBadge.d.ts +13 -0
- package/Badge/useBadge.js +41 -0
- package/Badge/useBadge.types.d.ts +40 -0
- package/Badge/useBadge.types.js +1 -0
- package/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/Breadcrumbs/Breadcrumbs.js +1 -1
- package/CHANGELOG.md +35 -0
- package/ClickAwayListener/ClickAwayListener.d.ts +47 -0
- package/ClickAwayListener/ClickAwayListener.js +178 -0
- package/ClickAwayListener/index.d.ts +2 -2
- package/ClickAwayListener/index.js +1 -1
- package/InputBase/InputBase.js +2 -2
- package/ListItem/ListItem.js +1 -1
- package/Menu/Menu.js +1 -1
- package/Modal/Modal.d.ts +1 -1
- package/Modal/Modal.js +2 -2
- package/Modal/ModalManager.d.ts +25 -0
- package/Modal/ModalManager.js +213 -0
- package/Modal/index.d.ts +1 -1
- package/Modal/index.js +1 -1
- package/Modal/useModal.d.ts +13 -0
- package/Modal/useModal.js +195 -0
- package/Modal/useModal.types.d.ts +115 -0
- package/Modal/useModal.types.js +1 -0
- package/NoSsr/NoSsr.d.ts +25 -0
- package/NoSsr/NoSsr.js +73 -0
- package/NoSsr/NoSsr.types.d.ts +18 -0
- package/NoSsr/NoSsr.types.js +1 -0
- package/NoSsr/index.d.ts +3 -2
- package/NoSsr/index.js +1 -1
- package/Popover/Popover.js +2 -1
- package/Popper/BasePopper.d.ts +7 -0
- package/Popper/BasePopper.js +372 -0
- package/Popper/BasePopper.types.d.ts +130 -0
- package/Popper/BasePopper.types.js +1 -0
- package/Popper/Popper.d.ts +1 -1
- package/Popper/Popper.js +1 -1
- package/Popper/index.d.ts +2 -1
- package/Popper/index.js +2 -1
- package/Popper/popperClasses.d.ts +8 -0
- package/Popper/popperClasses.js +7 -0
- package/Portal/Portal.d.ts +16 -0
- package/Portal/Portal.js +92 -0
- package/Portal/Portal.types.d.ts +23 -0
- package/Portal/Portal.types.js +1 -0
- package/Portal/index.d.ts +3 -2
- package/Portal/index.js +1 -1
- package/Slider/Slider.d.ts +2 -2
- package/Slider/Slider.js +3 -2
- package/Slider/useSlider.d.ts +14 -0
- package/Slider/useSlider.js +655 -0
- package/Slider/useSlider.types.d.ts +228 -0
- package/Slider/useSlider.types.js +1 -0
- package/Snackbar/Snackbar.d.ts +1 -1
- package/Snackbar/Snackbar.js +4 -5
- package/Snackbar/useSnackbar.d.ts +14 -0
- package/Snackbar/useSnackbar.js +131 -0
- package/Snackbar/useSnackbar.types.d.ts +60 -0
- package/Snackbar/useSnackbar.types.js +1 -0
- package/SwipeableDrawer/SwipeableDrawer.js +1 -1
- package/TabScrollButton/TabScrollButton.d.ts +1 -1
- package/TabScrollButton/TabScrollButton.js +1 -1
- package/TablePagination/TablePagination.js +1 -1
- package/Tabs/Tabs.d.ts +1 -1
- package/Tabs/Tabs.js +1 -1
- package/TextareaAutosize/TextareaAutosize.d.ts +14 -0
- package/TextareaAutosize/TextareaAutosize.js +223 -0
- package/TextareaAutosize/TextareaAutosize.types.d.ts +13 -0
- package/TextareaAutosize/TextareaAutosize.types.js +1 -0
- package/TextareaAutosize/index.d.ts +3 -2
- package/TextareaAutosize/index.js +1 -1
- package/Tooltip/Tooltip.js +2 -3
- package/Unstable_TrapFocus/FocusTrap.d.ts +10 -0
- package/Unstable_TrapFocus/FocusTrap.js +332 -0
- package/Unstable_TrapFocus/FocusTrap.types.d.ts +51 -0
- package/Unstable_TrapFocus/FocusTrap.types.js +1 -0
- package/Unstable_TrapFocus/index.d.ts +2 -2
- package/Unstable_TrapFocus/index.js +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/legacy/Autocomplete/Autocomplete.js +1 -1
- package/legacy/Badge/Badge.js +2 -2
- package/legacy/Badge/useBadge.js +42 -0
- package/legacy/Badge/useBadge.types.js +1 -0
- package/legacy/Breadcrumbs/Breadcrumbs.js +1 -1
- package/legacy/ClickAwayListener/ClickAwayListener.js +181 -0
- package/legacy/ClickAwayListener/index.js +1 -1
- package/legacy/InputBase/InputBase.js +2 -2
- package/legacy/ListItem/ListItem.js +1 -1
- package/legacy/Menu/Menu.js +1 -1
- package/legacy/Modal/Modal.js +2 -2
- package/legacy/Modal/ModalManager.js +233 -0
- package/legacy/Modal/index.js +1 -1
- package/legacy/Modal/useModal.js +206 -0
- package/legacy/Modal/useModal.types.js +1 -0
- package/legacy/NoSsr/NoSsr.js +75 -0
- package/legacy/NoSsr/NoSsr.types.js +1 -0
- package/legacy/NoSsr/index.js +1 -1
- package/legacy/Popover/Popover.js +2 -1
- package/legacy/Popper/BasePopper.js +380 -0
- package/legacy/Popper/BasePopper.types.js +1 -0
- package/legacy/Popper/Popper.js +1 -1
- package/legacy/Popper/index.js +2 -1
- package/legacy/Popper/popperClasses.js +7 -0
- package/legacy/Portal/Portal.js +92 -0
- package/legacy/Portal/Portal.types.js +1 -0
- package/legacy/Portal/index.js +1 -1
- package/legacy/Slider/Slider.js +3 -2
- package/legacy/Slider/useSlider.js +701 -0
- package/legacy/Slider/useSlider.types.js +1 -0
- package/legacy/Snackbar/Snackbar.js +4 -5
- package/legacy/Snackbar/useSnackbar.js +141 -0
- package/legacy/Snackbar/useSnackbar.types.js +1 -0
- package/legacy/SwipeableDrawer/SwipeableDrawer.js +1 -1
- package/legacy/TabScrollButton/TabScrollButton.js +1 -1
- package/legacy/TablePagination/TablePagination.js +1 -1
- package/legacy/Tabs/Tabs.js +1 -1
- package/legacy/TextareaAutosize/TextareaAutosize.js +220 -0
- package/legacy/TextareaAutosize/TextareaAutosize.types.js +1 -0
- package/legacy/TextareaAutosize/index.js +1 -1
- package/legacy/Tooltip/Tooltip.js +2 -3
- package/legacy/Unstable_TrapFocus/FocusTrap.js +341 -0
- package/legacy/Unstable_TrapFocus/FocusTrap.types.js +1 -0
- package/legacy/Unstable_TrapFocus/index.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/useAutocomplete/useAutocomplete.js +1078 -2
- package/legacy/utils/PolymorphicComponent.js +1 -0
- package/legacy/utils/areArraysEqual.js +9 -0
- package/legacy/utils/index.js +1 -1
- package/legacy/utils/shouldSpreadAdditionalProps.js +1 -1
- package/legacy/utils/useSlot.js +3 -1
- package/modern/Autocomplete/Autocomplete.js +1 -1
- package/modern/Badge/Badge.js +2 -2
- package/modern/Badge/useBadge.js +41 -0
- package/modern/Badge/useBadge.types.js +1 -0
- package/modern/Breadcrumbs/Breadcrumbs.js +1 -1
- package/modern/ClickAwayListener/ClickAwayListener.js +178 -0
- package/modern/ClickAwayListener/index.js +1 -1
- package/modern/InputBase/InputBase.js +2 -2
- package/modern/ListItem/ListItem.js +1 -1
- package/modern/Menu/Menu.js +1 -1
- package/modern/Modal/Modal.js +2 -2
- package/modern/Modal/ModalManager.js +213 -0
- package/modern/Modal/index.js +1 -1
- package/modern/Modal/useModal.js +193 -0
- package/modern/Modal/useModal.types.js +1 -0
- package/modern/NoSsr/NoSsr.js +73 -0
- package/modern/NoSsr/NoSsr.types.js +1 -0
- package/modern/NoSsr/index.js +1 -1
- package/modern/Popover/Popover.js +2 -1
- package/modern/Popper/BasePopper.js +371 -0
- package/modern/Popper/BasePopper.types.js +1 -0
- package/modern/Popper/Popper.js +1 -1
- package/modern/Popper/index.js +2 -1
- package/modern/Popper/popperClasses.js +7 -0
- package/modern/Portal/Portal.js +92 -0
- package/modern/Portal/Portal.types.js +1 -0
- package/modern/Portal/index.js +1 -1
- package/modern/Slider/Slider.js +3 -2
- package/modern/Slider/useSlider.js +643 -0
- package/modern/Slider/useSlider.types.js +1 -0
- package/modern/Snackbar/Snackbar.js +4 -5
- package/modern/Snackbar/useSnackbar.js +131 -0
- package/modern/Snackbar/useSnackbar.types.js +1 -0
- package/modern/SwipeableDrawer/SwipeableDrawer.js +1 -1
- package/modern/TabScrollButton/TabScrollButton.js +1 -1
- package/modern/TablePagination/TablePagination.js +1 -1
- package/modern/Tabs/Tabs.js +1 -1
- package/modern/TextareaAutosize/TextareaAutosize.js +223 -0
- package/modern/TextareaAutosize/TextareaAutosize.types.js +1 -0
- package/modern/TextareaAutosize/index.js +1 -1
- package/modern/Tooltip/Tooltip.js +2 -3
- package/modern/Unstable_TrapFocus/FocusTrap.js +331 -0
- package/modern/Unstable_TrapFocus/FocusTrap.types.js +1 -0
- package/modern/Unstable_TrapFocus/index.js +1 -1
- package/modern/index.js +2 -2
- package/modern/useAutocomplete/useAutocomplete.js +987 -2
- package/modern/utils/PolymorphicComponent.js +1 -0
- package/modern/utils/areArraysEqual.js +4 -0
- package/modern/utils/index.js +1 -1
- package/modern/utils/shouldSpreadAdditionalProps.js +1 -1
- package/modern/utils/useSlot.js +3 -1
- package/node/Autocomplete/Autocomplete.js +3 -3
- package/node/Badge/Badge.js +5 -5
- package/node/Badge/useBadge.js +46 -0
- package/node/Badge/useBadge.types.js +5 -0
- package/node/Breadcrumbs/Breadcrumbs.js +2 -2
- package/node/ClickAwayListener/ClickAwayListener.js +184 -0
- package/node/ClickAwayListener/index.js +1 -1
- package/node/InputBase/InputBase.js +7 -7
- package/node/ListItem/ListItem.js +3 -3
- package/node/Menu/Menu.js +3 -3
- package/node/Modal/Modal.js +5 -5
- package/node/Modal/ModalManager.js +221 -0
- package/node/Modal/index.js +2 -2
- package/node/Modal/useModal.js +203 -0
- package/node/Modal/useModal.types.js +5 -0
- package/node/NoSsr/NoSsr.js +81 -0
- package/node/NoSsr/NoSsr.types.js +5 -0
- package/node/NoSsr/index.js +3 -2
- package/node/Popover/Popover.js +5 -4
- package/node/Popper/BasePopper.js +380 -0
- package/node/Popper/BasePopper.types.js +5 -0
- package/node/Popper/Popper.js +2 -2
- package/node/Popper/index.js +14 -1
- package/node/Popper/popperClasses.js +15 -0
- package/node/Portal/Portal.js +100 -0
- package/node/Portal/Portal.types.js +5 -0
- package/node/Portal/index.js +3 -2
- package/node/Slider/Slider.js +14 -13
- package/node/Slider/useSlider.js +666 -0
- package/node/Slider/useSlider.types.js +5 -0
- package/node/Snackbar/Snackbar.js +9 -10
- package/node/Snackbar/useSnackbar.js +139 -0
- package/node/Snackbar/useSnackbar.types.js +5 -0
- package/node/SwipeableDrawer/SwipeableDrawer.js +2 -2
- package/node/TabScrollButton/TabScrollButton.js +3 -3
- package/node/TablePagination/TablePagination.js +2 -2
- package/node/Tabs/Tabs.js +3 -3
- package/node/TextareaAutosize/TextareaAutosize.js +230 -0
- package/node/TextareaAutosize/TextareaAutosize.types.js +5 -0
- package/node/TextareaAutosize/index.js +3 -2
- package/node/Tooltip/Tooltip.js +10 -11
- package/node/Unstable_TrapFocus/FocusTrap.js +339 -0
- package/node/Unstable_TrapFocus/FocusTrap.types.js +5 -0
- package/node/Unstable_TrapFocus/index.js +3 -2
- package/node/index.js +3 -3
- package/node/useAutocomplete/useAutocomplete.js +997 -18
- package/node/utils/PolymorphicComponent.js +5 -0
- package/node/utils/areArraysEqual.js +10 -0
- package/node/utils/index.js +2 -2
- package/node/utils/shouldSpreadAdditionalProps.js +3 -2
- package/node/utils/useSlot.js +6 -4
- package/package.json +5 -5
- package/styles/overrides.d.ts +1 -1
- package/umd/material-ui.development.js +9190 -9248
- package/umd/material-ui.production.min.js +3 -3
- package/useAutocomplete/useAutocomplete.d.ts +460 -2
- package/useAutocomplete/useAutocomplete.js +994 -2
- package/utils/PolymorphicComponent.d.ts +17 -0
- package/utils/PolymorphicComponent.js +1 -0
- package/utils/areArraysEqual.d.ts +3 -0
- package/utils/areArraysEqual.js +4 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +1 -1
- package/utils/shouldSpreadAdditionalProps.js +1 -1
- package/utils/types.d.ts +2 -1
- package/utils/useSlot.js +3 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable consistent-return, jsx-a11y/no-noninteractive-tabindex */
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { exactProp, elementAcceptingRef, unstable_useForkRef as useForkRef, unstable_ownerDocument as ownerDocument } from '@mui/utils';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
// Inspired by https://github.com/focus-trap/tabbable
|
|
10
|
+
var candidatesSelector = ['input', 'select', 'textarea', 'a[href]', 'button', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'].join(',');
|
|
11
|
+
function getTabIndex(node) {
|
|
12
|
+
var tabindexAttr = parseInt(node.getAttribute('tabindex') || '', 10);
|
|
13
|
+
if (!Number.isNaN(tabindexAttr)) {
|
|
14
|
+
return tabindexAttr;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Browsers do not return `tabIndex` correctly for contentEditable nodes;
|
|
18
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=661108&q=contenteditable%20tabindex&can=2
|
|
19
|
+
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
20
|
+
// in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
|
21
|
+
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
|
22
|
+
// yet they are still part of the regular tab order; in FF, they get a default
|
|
23
|
+
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
|
24
|
+
// order, consider their tab index to be 0.
|
|
25
|
+
if (node.contentEditable === 'true' || (node.nodeName === 'AUDIO' || node.nodeName === 'VIDEO' || node.nodeName === 'DETAILS') && node.getAttribute('tabindex') === null) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
return node.tabIndex;
|
|
29
|
+
}
|
|
30
|
+
function isNonTabbableRadio(node) {
|
|
31
|
+
if (node.tagName !== 'INPUT' || node.type !== 'radio') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (!node.name) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
var getRadio = function getRadio(selector) {
|
|
38
|
+
return node.ownerDocument.querySelector("input[type=\"radio\"]".concat(selector));
|
|
39
|
+
};
|
|
40
|
+
var roving = getRadio("[name=\"".concat(node.name, "\"]:checked"));
|
|
41
|
+
if (!roving) {
|
|
42
|
+
roving = getRadio("[name=\"".concat(node.name, "\"]"));
|
|
43
|
+
}
|
|
44
|
+
return roving !== node;
|
|
45
|
+
}
|
|
46
|
+
function isNodeMatchingSelectorFocusable(node) {
|
|
47
|
+
if (node.disabled || node.tagName === 'INPUT' && node.type === 'hidden' || isNonTabbableRadio(node)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function defaultGetTabbable(root) {
|
|
53
|
+
var regularTabNodes = [];
|
|
54
|
+
var orderedTabNodes = [];
|
|
55
|
+
Array.from(root.querySelectorAll(candidatesSelector)).forEach(function (node, i) {
|
|
56
|
+
var nodeTabIndex = getTabIndex(node);
|
|
57
|
+
if (nodeTabIndex === -1 || !isNodeMatchingSelectorFocusable(node)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (nodeTabIndex === 0) {
|
|
61
|
+
regularTabNodes.push(node);
|
|
62
|
+
} else {
|
|
63
|
+
orderedTabNodes.push({
|
|
64
|
+
documentOrder: i,
|
|
65
|
+
tabIndex: nodeTabIndex,
|
|
66
|
+
node: node
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return orderedTabNodes.sort(function (a, b) {
|
|
71
|
+
return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
|
|
72
|
+
}).map(function (a) {
|
|
73
|
+
return a.node;
|
|
74
|
+
}).concat(regularTabNodes);
|
|
75
|
+
}
|
|
76
|
+
function defaultIsEnabled() {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @ignore - internal component.
|
|
82
|
+
*/
|
|
83
|
+
function FocusTrap(props) {
|
|
84
|
+
var children = props.children,
|
|
85
|
+
_props$disableAutoFoc = props.disableAutoFocus,
|
|
86
|
+
disableAutoFocus = _props$disableAutoFoc === void 0 ? false : _props$disableAutoFoc,
|
|
87
|
+
_props$disableEnforce = props.disableEnforceFocus,
|
|
88
|
+
disableEnforceFocus = _props$disableEnforce === void 0 ? false : _props$disableEnforce,
|
|
89
|
+
_props$disableRestore = props.disableRestoreFocus,
|
|
90
|
+
disableRestoreFocus = _props$disableRestore === void 0 ? false : _props$disableRestore,
|
|
91
|
+
_props$getTabbable = props.getTabbable,
|
|
92
|
+
getTabbable = _props$getTabbable === void 0 ? defaultGetTabbable : _props$getTabbable,
|
|
93
|
+
_props$isEnabled = props.isEnabled,
|
|
94
|
+
isEnabled = _props$isEnabled === void 0 ? defaultIsEnabled : _props$isEnabled,
|
|
95
|
+
open = props.open;
|
|
96
|
+
var ignoreNextEnforceFocus = React.useRef(false);
|
|
97
|
+
var sentinelStart = React.useRef(null);
|
|
98
|
+
var sentinelEnd = React.useRef(null);
|
|
99
|
+
var nodeToRestore = React.useRef(null);
|
|
100
|
+
var reactFocusEventTarget = React.useRef(null);
|
|
101
|
+
// This variable is useful when disableAutoFocus is true.
|
|
102
|
+
// It waits for the active element to move into the component to activate.
|
|
103
|
+
var activated = React.useRef(false);
|
|
104
|
+
var rootRef = React.useRef(null);
|
|
105
|
+
// @ts-expect-error TODO upstream fix
|
|
106
|
+
var handleRef = useForkRef(children.ref, rootRef);
|
|
107
|
+
var lastKeydown = React.useRef(null);
|
|
108
|
+
React.useEffect(function () {
|
|
109
|
+
// We might render an empty child.
|
|
110
|
+
if (!open || !rootRef.current) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
activated.current = !disableAutoFocus;
|
|
114
|
+
}, [disableAutoFocus, open]);
|
|
115
|
+
React.useEffect(function () {
|
|
116
|
+
// We might render an empty child.
|
|
117
|
+
if (!open || !rootRef.current) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
var doc = ownerDocument(rootRef.current);
|
|
121
|
+
if (!rootRef.current.contains(doc.activeElement)) {
|
|
122
|
+
if (!rootRef.current.hasAttribute('tabIndex')) {
|
|
123
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
124
|
+
console.error(['MUI: The modal content node does not accept focus.', 'For the benefit of assistive technologies, ' + 'the tabIndex of the node is being set to "-1".'].join('\n'));
|
|
125
|
+
}
|
|
126
|
+
rootRef.current.setAttribute('tabIndex', '-1');
|
|
127
|
+
}
|
|
128
|
+
if (activated.current) {
|
|
129
|
+
rootRef.current.focus();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return function () {
|
|
133
|
+
// restoreLastFocus()
|
|
134
|
+
if (!disableRestoreFocus) {
|
|
135
|
+
// In IE11 it is possible for document.activeElement to be null resulting
|
|
136
|
+
// in nodeToRestore.current being null.
|
|
137
|
+
// Not all elements in IE11 have a focus method.
|
|
138
|
+
// Once IE11 support is dropped the focus() call can be unconditional.
|
|
139
|
+
if (nodeToRestore.current && nodeToRestore.current.focus) {
|
|
140
|
+
ignoreNextEnforceFocus.current = true;
|
|
141
|
+
nodeToRestore.current.focus();
|
|
142
|
+
}
|
|
143
|
+
nodeToRestore.current = null;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
// Missing `disableRestoreFocus` which is fine.
|
|
147
|
+
// We don't support changing that prop on an open FocusTrap
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
}, [open]);
|
|
150
|
+
React.useEffect(function () {
|
|
151
|
+
// We might render an empty child.
|
|
152
|
+
if (!open || !rootRef.current) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
var doc = ownerDocument(rootRef.current);
|
|
156
|
+
var loopFocus = function loopFocus(nativeEvent) {
|
|
157
|
+
lastKeydown.current = nativeEvent;
|
|
158
|
+
if (disableEnforceFocus || !isEnabled() || nativeEvent.key !== 'Tab') {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Make sure the next tab starts from the right place.
|
|
163
|
+
// doc.activeElement refers to the origin.
|
|
164
|
+
if (doc.activeElement === rootRef.current && nativeEvent.shiftKey) {
|
|
165
|
+
// We need to ignore the next contain as
|
|
166
|
+
// it will try to move the focus back to the rootRef element.
|
|
167
|
+
ignoreNextEnforceFocus.current = true;
|
|
168
|
+
if (sentinelEnd.current) {
|
|
169
|
+
sentinelEnd.current.focus();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var contain = function contain() {
|
|
174
|
+
var rootElement = rootRef.current;
|
|
175
|
+
|
|
176
|
+
// Cleanup functions are executed lazily in React 17.
|
|
177
|
+
// Contain can be called between the component being unmounted and its cleanup function being run.
|
|
178
|
+
if (rootElement === null) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!doc.hasFocus() || !isEnabled() || ignoreNextEnforceFocus.current) {
|
|
182
|
+
ignoreNextEnforceFocus.current = false;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The focus is already inside
|
|
187
|
+
if (rootElement.contains(doc.activeElement)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// The disableEnforceFocus is set and the focus is outside of the focus trap (and sentinel nodes)
|
|
192
|
+
if (disableEnforceFocus && doc.activeElement !== sentinelStart.current && doc.activeElement !== sentinelEnd.current) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// if the focus event is not coming from inside the children's react tree, reset the refs
|
|
197
|
+
if (doc.activeElement !== reactFocusEventTarget.current) {
|
|
198
|
+
reactFocusEventTarget.current = null;
|
|
199
|
+
} else if (reactFocusEventTarget.current !== null) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!activated.current) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
var tabbable = [];
|
|
206
|
+
if (doc.activeElement === sentinelStart.current || doc.activeElement === sentinelEnd.current) {
|
|
207
|
+
tabbable = getTabbable(rootRef.current);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// one of the sentinel nodes was focused, so move the focus
|
|
211
|
+
// to the first/last tabbable element inside the focus trap
|
|
212
|
+
if (tabbable.length > 0) {
|
|
213
|
+
var _lastKeydown$current, _lastKeydown$current2;
|
|
214
|
+
var isShiftTab = Boolean(((_lastKeydown$current = lastKeydown.current) == null ? void 0 : _lastKeydown$current.shiftKey) && ((_lastKeydown$current2 = lastKeydown.current) == null ? void 0 : _lastKeydown$current2.key) === 'Tab');
|
|
215
|
+
var focusNext = tabbable[0];
|
|
216
|
+
var focusPrevious = tabbable[tabbable.length - 1];
|
|
217
|
+
if (typeof focusNext !== 'string' && typeof focusPrevious !== 'string') {
|
|
218
|
+
if (isShiftTab) {
|
|
219
|
+
focusPrevious.focus();
|
|
220
|
+
} else {
|
|
221
|
+
focusNext.focus();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// no tabbable elements in the trap focus or the focus was outside of the focus trap
|
|
225
|
+
} else {
|
|
226
|
+
rootElement.focus();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
doc.addEventListener('focusin', contain);
|
|
230
|
+
doc.addEventListener('keydown', loopFocus, true);
|
|
231
|
+
|
|
232
|
+
// With Edge, Safari and Firefox, no focus related events are fired when the focused area stops being a focused area.
|
|
233
|
+
// for example https://bugzilla.mozilla.org/show_bug.cgi?id=559561.
|
|
234
|
+
// Instead, we can look if the active element was restored on the BODY element.
|
|
235
|
+
//
|
|
236
|
+
// The whatwg spec defines how the browser should behave but does not explicitly mention any events:
|
|
237
|
+
// https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule.
|
|
238
|
+
var interval = setInterval(function () {
|
|
239
|
+
if (doc.activeElement && doc.activeElement.tagName === 'BODY') {
|
|
240
|
+
contain();
|
|
241
|
+
}
|
|
242
|
+
}, 50);
|
|
243
|
+
return function () {
|
|
244
|
+
clearInterval(interval);
|
|
245
|
+
doc.removeEventListener('focusin', contain);
|
|
246
|
+
doc.removeEventListener('keydown', loopFocus, true);
|
|
247
|
+
};
|
|
248
|
+
}, [disableAutoFocus, disableEnforceFocus, disableRestoreFocus, isEnabled, open, getTabbable]);
|
|
249
|
+
var onFocus = function onFocus(event) {
|
|
250
|
+
if (nodeToRestore.current === null) {
|
|
251
|
+
nodeToRestore.current = event.relatedTarget;
|
|
252
|
+
}
|
|
253
|
+
activated.current = true;
|
|
254
|
+
reactFocusEventTarget.current = event.target;
|
|
255
|
+
var childrenPropsHandler = children.props.onFocus;
|
|
256
|
+
if (childrenPropsHandler) {
|
|
257
|
+
childrenPropsHandler(event);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
var handleFocusSentinel = function handleFocusSentinel(event) {
|
|
261
|
+
if (nodeToRestore.current === null) {
|
|
262
|
+
nodeToRestore.current = event.relatedTarget;
|
|
263
|
+
}
|
|
264
|
+
activated.current = true;
|
|
265
|
+
};
|
|
266
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
267
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
268
|
+
tabIndex: open ? 0 : -1,
|
|
269
|
+
onFocus: handleFocusSentinel,
|
|
270
|
+
ref: sentinelStart,
|
|
271
|
+
"data-testid": "sentinelStart"
|
|
272
|
+
}), /*#__PURE__*/React.cloneElement(children, {
|
|
273
|
+
ref: handleRef,
|
|
274
|
+
onFocus: onFocus
|
|
275
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
276
|
+
tabIndex: open ? 0 : -1,
|
|
277
|
+
onFocus: handleFocusSentinel,
|
|
278
|
+
ref: sentinelEnd,
|
|
279
|
+
"data-testid": "sentinelEnd"
|
|
280
|
+
})]
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
process.env.NODE_ENV !== "production" ? FocusTrap.propTypes /* remove-proptypes */ = {
|
|
284
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
285
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
286
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
287
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
288
|
+
/**
|
|
289
|
+
* A single child content element.
|
|
290
|
+
*/
|
|
291
|
+
children: elementAcceptingRef,
|
|
292
|
+
/**
|
|
293
|
+
* If `true`, the focus trap will not automatically shift focus to itself when it opens, and
|
|
294
|
+
* replace it to the last focused element when it closes.
|
|
295
|
+
* This also works correctly with any focus trap children that have the `disableAutoFocus` prop.
|
|
296
|
+
*
|
|
297
|
+
* Generally this should never be set to `true` as it makes the focus trap less
|
|
298
|
+
* accessible to assistive technologies, like screen readers.
|
|
299
|
+
* @default false
|
|
300
|
+
*/
|
|
301
|
+
disableAutoFocus: PropTypes.bool,
|
|
302
|
+
/**
|
|
303
|
+
* If `true`, the focus trap will not prevent focus from leaving the focus trap while open.
|
|
304
|
+
*
|
|
305
|
+
* Generally this should never be set to `true` as it makes the focus trap less
|
|
306
|
+
* accessible to assistive technologies, like screen readers.
|
|
307
|
+
* @default false
|
|
308
|
+
*/
|
|
309
|
+
disableEnforceFocus: PropTypes.bool,
|
|
310
|
+
/**
|
|
311
|
+
* If `true`, the focus trap will not restore focus to previously focused element once
|
|
312
|
+
* focus trap is hidden or unmounted.
|
|
313
|
+
* @default false
|
|
314
|
+
*/
|
|
315
|
+
disableRestoreFocus: PropTypes.bool,
|
|
316
|
+
/**
|
|
317
|
+
* Returns an array of ordered tabbable nodes (i.e. in tab order) within the root.
|
|
318
|
+
* For instance, you can provide the "tabbable" npm dependency.
|
|
319
|
+
* @param {HTMLElement} root
|
|
320
|
+
*/
|
|
321
|
+
getTabbable: PropTypes.func,
|
|
322
|
+
/**
|
|
323
|
+
* This prop extends the `open` prop.
|
|
324
|
+
* It allows to toggle the open state without having to wait for a rerender when changing the `open` prop.
|
|
325
|
+
* This prop should be memoized.
|
|
326
|
+
* It can be used to support multiple focus trap mounted at the same time.
|
|
327
|
+
* @default function defaultIsEnabled(): boolean {
|
|
328
|
+
* return true;
|
|
329
|
+
* }
|
|
330
|
+
*/
|
|
331
|
+
isEnabled: PropTypes.func,
|
|
332
|
+
/**
|
|
333
|
+
* If `true`, focus is locked.
|
|
334
|
+
*/
|
|
335
|
+
open: PropTypes.bool.isRequired
|
|
336
|
+
} : void 0;
|
|
337
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
338
|
+
// eslint-disable-next-line
|
|
339
|
+
FocusTrap['propTypes' + ''] = exactProp(FocusTrap.propTypes);
|
|
340
|
+
}
|
|
341
|
+
export default FocusTrap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { default } from './FocusTrap';
|
package/legacy/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/material v5.16.
|
|
2
|
+
* @mui/material v5.16.3
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -281,7 +281,7 @@ export * from './Zoom';
|
|
|
281
281
|
export { default as useAutocomplete } from './useAutocomplete';
|
|
282
282
|
export { default as GlobalStyles } from './GlobalStyles';
|
|
283
283
|
export * from './GlobalStyles';
|
|
284
|
-
export { unstable_composeClasses } from '@mui/
|
|
284
|
+
export { unstable_composeClasses } from '@mui/utils';
|
|
285
285
|
export { default as generateUtilityClass } from './generateUtilityClass';
|
|
286
286
|
export * from './generateUtilityClass';
|
|
287
287
|
export { default as generateUtilityClasses } from './generateUtilityClasses';
|