@mui/material 6.0.0-beta.0 → 6.0.0-beta.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/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 +32 -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 +1 -1
- package/Modal/ModalManager.d.ts +25 -0
- package/Modal/ModalManager.js +211 -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 +1 -1
- package/Popper/BasePopper.d.ts +7 -0
- package/Popper/BasePopper.js +370 -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 +647 -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 +3 -3
- package/Snackbar/useSnackbar.d.ts +14 -0
- package/Snackbar/useSnackbar.js +133 -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 +222 -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 +1 -1
- package/Unstable_TrapFocus/FocusTrap.d.ts +10 -0
- package/Unstable_TrapFocus/FocusTrap.js +330 -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/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 +1 -1
- package/modern/Modal/ModalManager.js +211 -0
- package/modern/Modal/index.js +1 -1
- package/modern/Modal/useModal.js +195 -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 +1 -1
- package/modern/Popper/BasePopper.js +370 -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 +647 -0
- package/modern/Slider/useSlider.types.js +1 -0
- package/modern/Snackbar/Snackbar.js +3 -3
- package/modern/Snackbar/useSnackbar.js +133 -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 +222 -0
- package/modern/TextareaAutosize/TextareaAutosize.types.js +1 -0
- package/modern/TextareaAutosize/index.js +1 -1
- package/modern/Tooltip/Tooltip.js +1 -1
- package/modern/Unstable_TrapFocus/FocusTrap.js +330 -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 +976 -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/isHostComponent.js +7 -0
- package/modern/utils/omitEventHandlers.js +18 -0
- 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 +2 -2
- package/node/Modal/ModalManager.js +219 -0
- package/node/Modal/index.js +2 -2
- package/node/Modal/useModal.js +205 -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 +2 -2
- package/node/Popper/BasePopper.js +379 -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 +670 -0
- package/node/Slider/useSlider.types.js +5 -0
- package/node/Snackbar/Snackbar.js +6 -6
- package/node/Snackbar/useSnackbar.js +141 -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 +5 -5
- 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 +985 -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/isHostComponent.js +13 -0
- package/node/utils/omitEventHandlers.js +24 -0
- package/node/utils/shouldSpreadAdditionalProps.js +3 -2
- package/node/utils/useSlot.js +6 -4
- package/package.json +6 -7
- package/styles/overrides.d.ts +1 -1
- package/useAutocomplete/useAutocomplete.d.ts +468 -2
- package/useAutocomplete/useAutocomplete.js +976 -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/isHostComponent.d.ts +6 -0
- package/utils/isHostComponent.js +7 -0
- package/utils/omitEventHandlers.d.ts +9 -0
- package/utils/omitEventHandlers.js +18 -0
- package/utils/shouldSpreadAdditionalProps.js +1 -1
- package/utils/types.d.ts +2 -1
- package/utils/useSlot.js +3 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { unstable_useEventCallback as useEventCallback, unstable_useTimeout as useTimeout } from '@mui/utils';
|
|
5
|
+
import extractEventHandlers from '@mui/utils/extractEventHandlers';
|
|
6
|
+
/**
|
|
7
|
+
* The basic building block for creating custom snackbar.
|
|
8
|
+
*
|
|
9
|
+
* Demos:
|
|
10
|
+
*
|
|
11
|
+
* - [Snackbar](https://next.mui.com/base-ui/react-snackbar/#hook)
|
|
12
|
+
*
|
|
13
|
+
* API:
|
|
14
|
+
*
|
|
15
|
+
* - [useSnackbar API](https://next.mui.com/base-ui/react-snackbar/hooks-api/#use-snackbar)
|
|
16
|
+
*/
|
|
17
|
+
function useSnackbar(parameters = {}) {
|
|
18
|
+
const {
|
|
19
|
+
autoHideDuration = null,
|
|
20
|
+
disableWindowBlurListener = false,
|
|
21
|
+
onClose,
|
|
22
|
+
open,
|
|
23
|
+
resumeHideDuration
|
|
24
|
+
} = parameters;
|
|
25
|
+
const timerAutoHide = useTimeout();
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (!open) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {KeyboardEvent} nativeEvent
|
|
33
|
+
*/
|
|
34
|
+
function handleKeyDown(nativeEvent) {
|
|
35
|
+
if (!nativeEvent.defaultPrevented) {
|
|
36
|
+
if (nativeEvent.key === 'Escape') {
|
|
37
|
+
// not calling `preventDefault` since we don't know if people may ignore this event e.g. a permanently open snackbar
|
|
38
|
+
onClose?.(nativeEvent, 'escapeKeyDown');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
43
|
+
return () => {
|
|
44
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
45
|
+
};
|
|
46
|
+
}, [open, onClose]);
|
|
47
|
+
const handleClose = useEventCallback((event, reason) => {
|
|
48
|
+
onClose?.(event, reason);
|
|
49
|
+
});
|
|
50
|
+
const setAutoHideTimer = useEventCallback(autoHideDurationParam => {
|
|
51
|
+
if (!onClose || autoHideDurationParam == null) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
timerAutoHide.start(autoHideDurationParam, () => {
|
|
55
|
+
handleClose(null, 'timeout');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
if (open) {
|
|
60
|
+
setAutoHideTimer(autoHideDuration);
|
|
61
|
+
}
|
|
62
|
+
return timerAutoHide.clear;
|
|
63
|
+
}, [open, autoHideDuration, setAutoHideTimer, timerAutoHide]);
|
|
64
|
+
const handleClickAway = event => {
|
|
65
|
+
onClose?.(event, 'clickaway');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Pause the timer when the user is interacting with the Snackbar
|
|
69
|
+
// or when the user hide the window.
|
|
70
|
+
const handlePause = timerAutoHide.clear;
|
|
71
|
+
|
|
72
|
+
// Restart the timer when the user is no longer interacting with the Snackbar
|
|
73
|
+
// or when the window is shown back.
|
|
74
|
+
const handleResume = React.useCallback(() => {
|
|
75
|
+
if (autoHideDuration != null) {
|
|
76
|
+
setAutoHideTimer(resumeHideDuration != null ? resumeHideDuration : autoHideDuration * 0.5);
|
|
77
|
+
}
|
|
78
|
+
}, [autoHideDuration, resumeHideDuration, setAutoHideTimer]);
|
|
79
|
+
const createHandleBlur = otherHandlers => event => {
|
|
80
|
+
const onBlurCallback = otherHandlers.onBlur;
|
|
81
|
+
onBlurCallback?.(event);
|
|
82
|
+
handleResume();
|
|
83
|
+
};
|
|
84
|
+
const createHandleFocus = otherHandlers => event => {
|
|
85
|
+
const onFocusCallback = otherHandlers.onFocus;
|
|
86
|
+
onFocusCallback?.(event);
|
|
87
|
+
handlePause();
|
|
88
|
+
};
|
|
89
|
+
const createMouseEnter = otherHandlers => event => {
|
|
90
|
+
const onMouseEnterCallback = otherHandlers.onMouseEnter;
|
|
91
|
+
onMouseEnterCallback?.(event);
|
|
92
|
+
handlePause();
|
|
93
|
+
};
|
|
94
|
+
const createMouseLeave = otherHandlers => event => {
|
|
95
|
+
const onMouseLeaveCallback = otherHandlers.onMouseLeave;
|
|
96
|
+
onMouseLeaveCallback?.(event);
|
|
97
|
+
handleResume();
|
|
98
|
+
};
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
// TODO: window global should be refactored here
|
|
101
|
+
if (!disableWindowBlurListener && open) {
|
|
102
|
+
window.addEventListener('focus', handleResume);
|
|
103
|
+
window.addEventListener('blur', handlePause);
|
|
104
|
+
return () => {
|
|
105
|
+
window.removeEventListener('focus', handleResume);
|
|
106
|
+
window.removeEventListener('blur', handlePause);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}, [disableWindowBlurListener, open, handleResume, handlePause]);
|
|
111
|
+
const getRootProps = (externalProps = {}) => {
|
|
112
|
+
const externalEventHandlers = {
|
|
113
|
+
...extractEventHandlers(parameters),
|
|
114
|
+
...extractEventHandlers(externalProps)
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
// ClickAwayListener adds an `onClick` prop which results in the alert not being announced.
|
|
118
|
+
// See https://github.com/mui/material-ui/issues/29080
|
|
119
|
+
role: 'presentation',
|
|
120
|
+
...externalProps,
|
|
121
|
+
...externalEventHandlers,
|
|
122
|
+
onBlur: createHandleBlur(externalEventHandlers),
|
|
123
|
+
onFocus: createHandleFocus(externalEventHandlers),
|
|
124
|
+
onMouseEnter: createMouseEnter(externalEventHandlers),
|
|
125
|
+
onMouseLeave: createMouseLeave(externalEventHandlers)
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
getRootProps,
|
|
130
|
+
onClickAway: handleClickAway
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export default useSnackbar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import * as ReactDOM from 'react-dom';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
|
|
7
|
-
import
|
|
7
|
+
import NoSsr from '../NoSsr';
|
|
8
8
|
import Drawer, { getAnchor, isHorizontal } from '../Drawer/Drawer';
|
|
9
9
|
import useForkRef from '../utils/useForkRef';
|
|
10
10
|
import ownerDocument from '../utils/ownerDocument';
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
import { useSlotProps } from '@mui/base/utils';
|
|
8
7
|
import composeClasses from '@mui/utils/composeClasses';
|
|
9
8
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
9
|
+
import useSlotProps from '@mui/utils/useSlotProps';
|
|
10
10
|
import KeyboardArrowLeft from '../internal/svg-icons/KeyboardArrowLeft';
|
|
11
11
|
import KeyboardArrowRight from '../internal/svg-icons/KeyboardArrowRight';
|
|
12
12
|
import ButtonBase from '../ButtonBase';
|
|
@@ -6,8 +6,8 @@ import PropTypes from 'prop-types';
|
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import integerPropType from '@mui/utils/integerPropType';
|
|
8
8
|
import chainPropTypes from '@mui/utils/chainPropTypes';
|
|
9
|
-
import { isHostComponent } from '@mui/base/utils';
|
|
10
9
|
import composeClasses from '@mui/utils/composeClasses';
|
|
10
|
+
import isHostComponent from '../utils/isHostComponent';
|
|
11
11
|
import { styled } from '../zero-styled';
|
|
12
12
|
import { useDefaultProps } from '../DefaultPropsProvider';
|
|
13
13
|
import InputBase from '../InputBase';
|
package/modern/Tabs/Tabs.js
CHANGED
|
@@ -5,9 +5,9 @@ import { isFragment } from 'react-is';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import refType from '@mui/utils/refType';
|
|
8
|
-
import { useSlotProps } from '@mui/base/utils';
|
|
9
8
|
import composeClasses from '@mui/utils/composeClasses';
|
|
10
9
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
10
|
+
import useSlotProps from '@mui/utils/useSlotProps';
|
|
11
11
|
import { styled, useTheme } from '../zero-styled';
|
|
12
12
|
import { useDefaultProps } from '../DefaultPropsProvider';
|
|
13
13
|
import debounce from '../utils/debounce';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { unstable_debounce as debounce, unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
function getStyleValue(value) {
|
|
8
|
+
return parseInt(value, 10) || 0;
|
|
9
|
+
}
|
|
10
|
+
const styles = {
|
|
11
|
+
shadow: {
|
|
12
|
+
// Visibility needed to hide the extra text area on iPads
|
|
13
|
+
visibility: 'hidden',
|
|
14
|
+
// Remove from the content flow
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
// Ignore the scrollbar width
|
|
17
|
+
overflow: 'hidden',
|
|
18
|
+
height: 0,
|
|
19
|
+
top: 0,
|
|
20
|
+
left: 0,
|
|
21
|
+
// Create a new layer, increase the isolation of the computed values
|
|
22
|
+
transform: 'translateZ(0)'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function isEmpty(obj) {
|
|
26
|
+
return obj === undefined || obj === null || Object.keys(obj).length === 0 || obj.outerHeightStyle === 0 && !obj.overflowing;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* Demos:
|
|
32
|
+
*
|
|
33
|
+
* - [Textarea Autosize](https://next.mui.com/material-ui/react-textarea-autosize/)
|
|
34
|
+
*
|
|
35
|
+
* API:
|
|
36
|
+
*
|
|
37
|
+
* - [TextareaAutosize API](https://next.mui.com/material-ui/api/textarea-autosize/)
|
|
38
|
+
*/
|
|
39
|
+
const TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize(props, forwardedRef) {
|
|
40
|
+
const {
|
|
41
|
+
onChange,
|
|
42
|
+
maxRows,
|
|
43
|
+
minRows = 1,
|
|
44
|
+
style,
|
|
45
|
+
value,
|
|
46
|
+
...other
|
|
47
|
+
} = props;
|
|
48
|
+
const {
|
|
49
|
+
current: isControlled
|
|
50
|
+
} = React.useRef(value != null);
|
|
51
|
+
const inputRef = React.useRef(null);
|
|
52
|
+
const handleRef = useForkRef(forwardedRef, inputRef);
|
|
53
|
+
const heightRef = React.useRef(null);
|
|
54
|
+
const shadowRef = React.useRef(null);
|
|
55
|
+
const calculateTextareaStyles = React.useCallback(() => {
|
|
56
|
+
const input = inputRef.current;
|
|
57
|
+
const containerWindow = ownerWindow(input);
|
|
58
|
+
const computedStyle = containerWindow.getComputedStyle(input);
|
|
59
|
+
|
|
60
|
+
// If input's width is shrunk and it's not visible, don't sync height.
|
|
61
|
+
if (computedStyle.width === '0px') {
|
|
62
|
+
return {
|
|
63
|
+
outerHeightStyle: 0,
|
|
64
|
+
overflowing: false
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const inputShallow = shadowRef.current;
|
|
68
|
+
inputShallow.style.width = computedStyle.width;
|
|
69
|
+
inputShallow.value = input.value || props.placeholder || 'x';
|
|
70
|
+
if (inputShallow.value.slice(-1) === '\n') {
|
|
71
|
+
// Certain fonts which overflow the line height will cause the textarea
|
|
72
|
+
// to report a different scrollHeight depending on whether the last line
|
|
73
|
+
// is empty. Make it non-empty to avoid this issue.
|
|
74
|
+
inputShallow.value += ' ';
|
|
75
|
+
}
|
|
76
|
+
const boxSizing = computedStyle.boxSizing;
|
|
77
|
+
const padding = getStyleValue(computedStyle.paddingBottom) + getStyleValue(computedStyle.paddingTop);
|
|
78
|
+
const border = getStyleValue(computedStyle.borderBottomWidth) + getStyleValue(computedStyle.borderTopWidth);
|
|
79
|
+
|
|
80
|
+
// The height of the inner content
|
|
81
|
+
const innerHeight = inputShallow.scrollHeight;
|
|
82
|
+
|
|
83
|
+
// Measure height of a textarea with a single row
|
|
84
|
+
inputShallow.value = 'x';
|
|
85
|
+
const singleRowHeight = inputShallow.scrollHeight;
|
|
86
|
+
|
|
87
|
+
// The height of the outer content
|
|
88
|
+
let outerHeight = innerHeight;
|
|
89
|
+
if (minRows) {
|
|
90
|
+
outerHeight = Math.max(Number(minRows) * singleRowHeight, outerHeight);
|
|
91
|
+
}
|
|
92
|
+
if (maxRows) {
|
|
93
|
+
outerHeight = Math.min(Number(maxRows) * singleRowHeight, outerHeight);
|
|
94
|
+
}
|
|
95
|
+
outerHeight = Math.max(outerHeight, singleRowHeight);
|
|
96
|
+
|
|
97
|
+
// Take the box sizing into account for applying this value as a style.
|
|
98
|
+
const outerHeightStyle = outerHeight + (boxSizing === 'border-box' ? padding + border : 0);
|
|
99
|
+
const overflowing = Math.abs(outerHeight - innerHeight) <= 1;
|
|
100
|
+
return {
|
|
101
|
+
outerHeightStyle,
|
|
102
|
+
overflowing
|
|
103
|
+
};
|
|
104
|
+
}, [maxRows, minRows, props.placeholder]);
|
|
105
|
+
const syncHeight = React.useCallback(() => {
|
|
106
|
+
const textareaStyles = calculateTextareaStyles();
|
|
107
|
+
if (isEmpty(textareaStyles)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const outerHeightStyle = textareaStyles.outerHeightStyle;
|
|
111
|
+
const input = inputRef.current;
|
|
112
|
+
if (heightRef.current !== outerHeightStyle) {
|
|
113
|
+
heightRef.current = outerHeightStyle;
|
|
114
|
+
input.style.height = `${outerHeightStyle}px`;
|
|
115
|
+
}
|
|
116
|
+
input.style.overflow = textareaStyles.overflowing ? 'hidden' : '';
|
|
117
|
+
}, [calculateTextareaStyles]);
|
|
118
|
+
useEnhancedEffect(() => {
|
|
119
|
+
const handleResize = () => {
|
|
120
|
+
syncHeight();
|
|
121
|
+
};
|
|
122
|
+
// Workaround a "ResizeObserver loop completed with undelivered notifications" error
|
|
123
|
+
// in test.
|
|
124
|
+
// Note that we might need to use this logic in production per https://github.com/WICG/resize-observer/issues/38
|
|
125
|
+
// Also see https://github.com/mui/mui-x/issues/8733
|
|
126
|
+
let rAF;
|
|
127
|
+
const rAFHandleResize = () => {
|
|
128
|
+
cancelAnimationFrame(rAF);
|
|
129
|
+
rAF = requestAnimationFrame(() => {
|
|
130
|
+
handleResize();
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const debounceHandleResize = debounce(handleResize);
|
|
134
|
+
const input = inputRef.current;
|
|
135
|
+
const containerWindow = ownerWindow(input);
|
|
136
|
+
containerWindow.addEventListener('resize', debounceHandleResize);
|
|
137
|
+
let resizeObserver;
|
|
138
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
139
|
+
resizeObserver = new ResizeObserver(process.env.NODE_ENV === 'test' ? rAFHandleResize : handleResize);
|
|
140
|
+
resizeObserver.observe(input);
|
|
141
|
+
}
|
|
142
|
+
return () => {
|
|
143
|
+
debounceHandleResize.clear();
|
|
144
|
+
cancelAnimationFrame(rAF);
|
|
145
|
+
containerWindow.removeEventListener('resize', debounceHandleResize);
|
|
146
|
+
if (resizeObserver) {
|
|
147
|
+
resizeObserver.disconnect();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}, [calculateTextareaStyles, syncHeight]);
|
|
151
|
+
useEnhancedEffect(() => {
|
|
152
|
+
syncHeight();
|
|
153
|
+
});
|
|
154
|
+
const handleChange = event => {
|
|
155
|
+
if (!isControlled) {
|
|
156
|
+
syncHeight();
|
|
157
|
+
}
|
|
158
|
+
if (onChange) {
|
|
159
|
+
onChange(event);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
163
|
+
children: [/*#__PURE__*/_jsx("textarea", {
|
|
164
|
+
value: value,
|
|
165
|
+
onChange: handleChange,
|
|
166
|
+
ref: handleRef
|
|
167
|
+
// Apply the rows prop to get a "correct" first SSR paint
|
|
168
|
+
,
|
|
169
|
+
rows: minRows,
|
|
170
|
+
style: style,
|
|
171
|
+
...other
|
|
172
|
+
}), /*#__PURE__*/_jsx("textarea", {
|
|
173
|
+
"aria-hidden": true,
|
|
174
|
+
className: props.className,
|
|
175
|
+
readOnly: true,
|
|
176
|
+
ref: shadowRef,
|
|
177
|
+
tabIndex: -1,
|
|
178
|
+
style: {
|
|
179
|
+
...styles.shadow,
|
|
180
|
+
...style,
|
|
181
|
+
paddingTop: 0,
|
|
182
|
+
paddingBottom: 0
|
|
183
|
+
}
|
|
184
|
+
})]
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
process.env.NODE_ENV !== "production" ? TextareaAutosize.propTypes /* remove-proptypes */ = {
|
|
188
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
189
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
190
|
+
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
|
|
191
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
192
|
+
/**
|
|
193
|
+
* @ignore
|
|
194
|
+
*/
|
|
195
|
+
className: PropTypes.string,
|
|
196
|
+
/**
|
|
197
|
+
* Maximum number of rows to display.
|
|
198
|
+
*/
|
|
199
|
+
maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
200
|
+
/**
|
|
201
|
+
* Minimum number of rows to display.
|
|
202
|
+
* @default 1
|
|
203
|
+
*/
|
|
204
|
+
minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
205
|
+
/**
|
|
206
|
+
* @ignore
|
|
207
|
+
*/
|
|
208
|
+
onChange: PropTypes.func,
|
|
209
|
+
/**
|
|
210
|
+
* @ignore
|
|
211
|
+
*/
|
|
212
|
+
placeholder: PropTypes.string,
|
|
213
|
+
/**
|
|
214
|
+
* @ignore
|
|
215
|
+
*/
|
|
216
|
+
style: PropTypes.object,
|
|
217
|
+
/**
|
|
218
|
+
* @ignore
|
|
219
|
+
*/
|
|
220
|
+
value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.number, PropTypes.string])
|
|
221
|
+
} : void 0;
|
|
222
|
+
export default TextareaAutosize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { default } from './TextareaAutosize';
|
|
@@ -5,11 +5,11 @@ import PropTypes from 'prop-types';
|
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import useTimeout, { Timeout } from '@mui/utils/useTimeout';
|
|
7
7
|
import elementAcceptingRef from '@mui/utils/elementAcceptingRef';
|
|
8
|
-
import { appendOwnerState } from '@mui/base/utils';
|
|
9
8
|
import composeClasses from '@mui/utils/composeClasses';
|
|
10
9
|
import { alpha } from '@mui/system/colorManipulator';
|
|
11
10
|
import { useRtl } from '@mui/system/RtlProvider';
|
|
12
11
|
import isFocusVisible from '@mui/utils/isFocusVisible';
|
|
12
|
+
import appendOwnerState from '@mui/utils/appendOwnerState';
|
|
13
13
|
import { styled, useTheme } from '../zero-styled';
|
|
14
14
|
import { useDefaultProps } from '../DefaultPropsProvider';
|
|
15
15
|
import capitalize from '../utils/capitalize';
|