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