@mui/material 5.16.13 → 5.17.0
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.js +49 -58
- package/CHANGELOG.md +27 -0
- package/TextareaAutosize/TextareaAutosize.js +66 -45
- package/index.js +1 -1
- package/legacy/Autocomplete/Autocomplete.js +51 -62
- package/legacy/TextareaAutosize/TextareaAutosize.js +66 -45
- package/legacy/index.js +1 -1
- package/legacy/styles/ThemeProvider.js +13 -1
- package/legacy/styles/createTheme.js +4 -1
- package/legacy/version/index.js +3 -3
- package/modern/Autocomplete/Autocomplete.js +49 -58
- package/modern/TextareaAutosize/TextareaAutosize.js +66 -45
- package/modern/index.js +1 -1
- package/modern/styles/ThemeProvider.js +13 -1
- package/modern/styles/createTheme.js +4 -1
- package/modern/version/index.js +3 -3
- package/node/Autocomplete/Autocomplete.js +49 -58
- package/node/TextareaAutosize/TextareaAutosize.js +65 -44
- package/node/index.js +1 -1
- package/node/styles/ThemeProvider.js +13 -1
- package/node/styles/createTheme.js +4 -1
- package/node/version/index.js +3 -3
- package/package.json +5 -5
- package/styles/ThemeProvider.js +13 -1
- package/styles/createTheme.js +4 -1
- package/umd/material-ui.development.js +136 -105
- package/umd/material-ui.production.min.js +2 -2
- package/version/index.js +3 -3
|
@@ -600,63 +600,6 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps
|
|
|
600
600
|
const paperSlotProps = (_slotProps$paper = slotProps.paper) != null ? _slotProps$paper : componentsProps.paper;
|
|
601
601
|
const popperSlotProps = (_slotProps$popper = slotProps.popper) != null ? _slotProps$popper : componentsProps.popper;
|
|
602
602
|
const popupIndicatorSlotProps = (_slotProps$popupIndic = slotProps.popupIndicator) != null ? _slotProps$popupIndic : componentsProps.popupIndicator;
|
|
603
|
-
const renderAutocompletePopperChildren = children => /*#__PURE__*/_jsx(AutocompletePopper, _extends({
|
|
604
|
-
as: PopperComponent,
|
|
605
|
-
disablePortal: disablePortal,
|
|
606
|
-
style: {
|
|
607
|
-
width: anchorEl ? anchorEl.clientWidth : null
|
|
608
|
-
},
|
|
609
|
-
ownerState: ownerState,
|
|
610
|
-
role: "presentation",
|
|
611
|
-
anchorEl: anchorEl,
|
|
612
|
-
open: popupOpen
|
|
613
|
-
}, popperSlotProps, {
|
|
614
|
-
className: clsx(classes.popper, popperSlotProps == null ? void 0 : popperSlotProps.className),
|
|
615
|
-
children: /*#__PURE__*/_jsx(AutocompletePaper, _extends({
|
|
616
|
-
ownerState: ownerState,
|
|
617
|
-
as: PaperComponent
|
|
618
|
-
}, paperSlotProps, {
|
|
619
|
-
className: clsx(classes.paper, paperSlotProps == null ? void 0 : paperSlotProps.className),
|
|
620
|
-
children: children
|
|
621
|
-
}))
|
|
622
|
-
}));
|
|
623
|
-
let autocompletePopper = null;
|
|
624
|
-
if (groupedOptions.length > 0) {
|
|
625
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteListbox, _extends({
|
|
626
|
-
as: ListboxComponent,
|
|
627
|
-
className: classes.listbox,
|
|
628
|
-
ownerState: ownerState
|
|
629
|
-
}, otherListboxProps, ListboxProps, {
|
|
630
|
-
ref: combinedListboxRef,
|
|
631
|
-
children: groupedOptions.map((option, index) => {
|
|
632
|
-
if (groupBy) {
|
|
633
|
-
return renderGroup({
|
|
634
|
-
key: option.key,
|
|
635
|
-
group: option.group,
|
|
636
|
-
children: option.options.map((option2, index2) => renderListOption(option2, option.index + index2))
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
return renderListOption(option, index);
|
|
640
|
-
})
|
|
641
|
-
})));
|
|
642
|
-
} else if (loading && groupedOptions.length === 0) {
|
|
643
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteLoading, {
|
|
644
|
-
className: classes.loading,
|
|
645
|
-
ownerState: ownerState,
|
|
646
|
-
children: loadingText
|
|
647
|
-
}));
|
|
648
|
-
} else if (groupedOptions.length === 0 && !freeSolo && !loading) {
|
|
649
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteNoOptions, {
|
|
650
|
-
className: classes.noOptions,
|
|
651
|
-
ownerState: ownerState,
|
|
652
|
-
role: "presentation",
|
|
653
|
-
onMouseDown: event => {
|
|
654
|
-
// Prevent input blur when interacting with the "no options" content
|
|
655
|
-
event.preventDefault();
|
|
656
|
-
},
|
|
657
|
-
children: noOptionsText
|
|
658
|
-
}));
|
|
659
|
-
}
|
|
660
603
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
661
604
|
children: [/*#__PURE__*/_jsx(AutocompleteRoot, _extends({
|
|
662
605
|
ref: ref,
|
|
@@ -706,7 +649,55 @@ const Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps
|
|
|
706
649
|
readOnly
|
|
707
650
|
}, getInputProps())
|
|
708
651
|
})
|
|
709
|
-
})), anchorEl ?
|
|
652
|
+
})), anchorEl ? /*#__PURE__*/_jsx(AutocompletePopper, _extends({
|
|
653
|
+
as: PopperComponent,
|
|
654
|
+
disablePortal: disablePortal,
|
|
655
|
+
style: {
|
|
656
|
+
width: anchorEl ? anchorEl.clientWidth : null
|
|
657
|
+
},
|
|
658
|
+
ownerState: ownerState,
|
|
659
|
+
role: "presentation",
|
|
660
|
+
anchorEl: anchorEl,
|
|
661
|
+
open: popupOpen
|
|
662
|
+
}, popperSlotProps, {
|
|
663
|
+
className: clsx(classes.popper, popperSlotProps == null ? void 0 : popperSlotProps.className),
|
|
664
|
+
children: /*#__PURE__*/_jsxs(AutocompletePaper, _extends({
|
|
665
|
+
ownerState: ownerState,
|
|
666
|
+
as: PaperComponent
|
|
667
|
+
}, paperSlotProps, {
|
|
668
|
+
className: clsx(classes.paper, paperSlotProps == null ? void 0 : paperSlotProps.className),
|
|
669
|
+
children: [loading && groupedOptions.length === 0 ? /*#__PURE__*/_jsx(AutocompleteLoading, {
|
|
670
|
+
className: classes.loading,
|
|
671
|
+
ownerState: ownerState,
|
|
672
|
+
children: loadingText
|
|
673
|
+
}) : null, groupedOptions.length === 0 && !freeSolo && !loading ? /*#__PURE__*/_jsx(AutocompleteNoOptions, {
|
|
674
|
+
className: classes.noOptions,
|
|
675
|
+
ownerState: ownerState,
|
|
676
|
+
role: "presentation",
|
|
677
|
+
onMouseDown: event => {
|
|
678
|
+
// Prevent input blur when interacting with the "no options" content
|
|
679
|
+
event.preventDefault();
|
|
680
|
+
},
|
|
681
|
+
children: noOptionsText
|
|
682
|
+
}) : null, groupedOptions.length > 0 ? /*#__PURE__*/_jsx(AutocompleteListbox, _extends({
|
|
683
|
+
as: ListboxComponent,
|
|
684
|
+
className: classes.listbox,
|
|
685
|
+
ownerState: ownerState
|
|
686
|
+
}, otherListboxProps, ListboxProps, {
|
|
687
|
+
ref: combinedListboxRef,
|
|
688
|
+
children: groupedOptions.map((option, index) => {
|
|
689
|
+
if (groupBy) {
|
|
690
|
+
return renderGroup({
|
|
691
|
+
key: option.key,
|
|
692
|
+
group: option.group,
|
|
693
|
+
children: option.options.map((option2, index2) => renderListOption(option2, option.index + index2))
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
return renderListOption(option, index);
|
|
697
|
+
})
|
|
698
|
+
})) : null]
|
|
699
|
+
}))
|
|
700
|
+
})) : null]
|
|
710
701
|
});
|
|
711
702
|
});
|
|
712
703
|
process.env.NODE_ENV !== "production" ? Autocomplete.propTypes /* remove-proptypes */ = {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## v5.17.0
|
|
4
|
+
|
|
5
|
+
_Mar 18, 2025_
|
|
6
|
+
|
|
7
|
+
A big thanks to the 2 contributors who made this release possible.
|
|
8
|
+
|
|
9
|
+
### `@mui/material@5.17.0`
|
|
10
|
+
|
|
11
|
+
- [TextareaAutosize] Temporarily disconnect ResizeObserver to avoid loop error (#44540) (#45238) @DiegoAndai
|
|
12
|
+
- Support nested theme when upper theme is CSS vars theme (#45604) @siriwatknp
|
|
13
|
+
|
|
14
|
+
All contributors of this release in alphabetical order: @DiegoAndai, @siriwatknp
|
|
15
|
+
|
|
16
|
+
## v5.16.14
|
|
17
|
+
|
|
18
|
+
<!-- generated comparing v5.16.13..v5.x -->
|
|
19
|
+
|
|
20
|
+
_Jan 6, 2025_
|
|
21
|
+
|
|
22
|
+
A big thanks to the 1 contributor who made this release possible.
|
|
23
|
+
|
|
24
|
+
### `@mui/material@5.16.14`
|
|
25
|
+
|
|
26
|
+
- [Autocomplete] Revert: Fix options list rendering in freeSolo mode (#44857) @ZeeshanTamboli
|
|
27
|
+
|
|
28
|
+
All contributors of this release in alphabetical order: @ZeeshanTamboli
|
|
29
|
+
|
|
3
30
|
## v5.16.13
|
|
4
31
|
|
|
5
32
|
<!-- generated comparing v5.16.12..v5.x -->
|
|
@@ -5,7 +5,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
5
5
|
const _excluded = ["onChange", "maxRows", "minRows", "style", "value"];
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
-
import { unstable_debounce as debounce, unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
8
|
+
import { unstable_debounce as debounce, unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
function getStyleValue(value) {
|
|
@@ -26,8 +26,15 @@ const styles = {
|
|
|
26
26
|
transform: 'translateZ(0)'
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
function isObjectEmpty(object) {
|
|
30
|
+
// eslint-disable-next-line
|
|
31
|
+
for (const _ in object) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
29
36
|
function isEmpty(obj) {
|
|
30
|
-
return
|
|
37
|
+
return isObjectEmpty(obj) || obj.outerHeightStyle === 0 && !obj.overflowing;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
/**
|
|
@@ -52,14 +59,18 @@ const TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize
|
|
|
52
59
|
const {
|
|
53
60
|
current: isControlled
|
|
54
61
|
} = React.useRef(value != null);
|
|
55
|
-
const
|
|
56
|
-
const handleRef = useForkRef(forwardedRef,
|
|
62
|
+
const textareaRef = React.useRef(null);
|
|
63
|
+
const handleRef = useForkRef(forwardedRef, textareaRef);
|
|
57
64
|
const heightRef = React.useRef(null);
|
|
58
|
-
const
|
|
65
|
+
const hiddenTextareaRef = React.useRef(null);
|
|
59
66
|
const calculateTextareaStyles = React.useCallback(() => {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
67
|
+
const textarea = textareaRef.current;
|
|
68
|
+
const hiddenTextarea = hiddenTextareaRef.current;
|
|
69
|
+
if (!textarea || !hiddenTextarea) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const containerWindow = ownerWindow(textarea);
|
|
73
|
+
const computedStyle = containerWindow.getComputedStyle(textarea);
|
|
63
74
|
|
|
64
75
|
// If input's width is shrunk and it's not visible, don't sync height.
|
|
65
76
|
if (computedStyle.width === '0px') {
|
|
@@ -68,25 +79,24 @@ const TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize
|
|
|
68
79
|
overflowing: false
|
|
69
80
|
};
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (inputShallow.value.slice(-1) === '\n') {
|
|
82
|
+
hiddenTextarea.style.width = computedStyle.width;
|
|
83
|
+
hiddenTextarea.value = textarea.value || props.placeholder || 'x';
|
|
84
|
+
if (hiddenTextarea.value.slice(-1) === '\n') {
|
|
75
85
|
// Certain fonts which overflow the line height will cause the textarea
|
|
76
86
|
// to report a different scrollHeight depending on whether the last line
|
|
77
87
|
// is empty. Make it non-empty to avoid this issue.
|
|
78
|
-
|
|
88
|
+
hiddenTextarea.value += ' ';
|
|
79
89
|
}
|
|
80
90
|
const boxSizing = computedStyle.boxSizing;
|
|
81
91
|
const padding = getStyleValue(computedStyle.paddingBottom) + getStyleValue(computedStyle.paddingTop);
|
|
82
92
|
const border = getStyleValue(computedStyle.borderBottomWidth) + getStyleValue(computedStyle.borderTopWidth);
|
|
83
93
|
|
|
84
94
|
// The height of the inner content
|
|
85
|
-
const innerHeight =
|
|
95
|
+
const innerHeight = hiddenTextarea.scrollHeight;
|
|
86
96
|
|
|
87
97
|
// Measure height of a textarea with a single row
|
|
88
|
-
|
|
89
|
-
const singleRowHeight =
|
|
98
|
+
hiddenTextarea.value = 'x';
|
|
99
|
+
const singleRowHeight = hiddenTextarea.scrollHeight;
|
|
90
100
|
|
|
91
101
|
// The height of the outer content
|
|
92
102
|
let outerHeight = innerHeight;
|
|
@@ -106,52 +116,63 @@ const TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize
|
|
|
106
116
|
overflowing
|
|
107
117
|
};
|
|
108
118
|
}, [maxRows, minRows, props.placeholder]);
|
|
119
|
+
const didHeightChange = useEventCallback(() => {
|
|
120
|
+
const textarea = textareaRef.current;
|
|
121
|
+
const textareaStyles = calculateTextareaStyles();
|
|
122
|
+
if (!textarea || !textareaStyles || isEmpty(textareaStyles)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const outerHeightStyle = textareaStyles.outerHeightStyle;
|
|
126
|
+
return heightRef.current != null && heightRef.current !== outerHeightStyle;
|
|
127
|
+
});
|
|
109
128
|
const syncHeight = React.useCallback(() => {
|
|
129
|
+
const textarea = textareaRef.current;
|
|
110
130
|
const textareaStyles = calculateTextareaStyles();
|
|
111
|
-
if (isEmpty(textareaStyles)) {
|
|
131
|
+
if (!textarea || !textareaStyles || isEmpty(textareaStyles)) {
|
|
112
132
|
return;
|
|
113
133
|
}
|
|
114
134
|
const outerHeightStyle = textareaStyles.outerHeightStyle;
|
|
115
|
-
const input = inputRef.current;
|
|
116
135
|
if (heightRef.current !== outerHeightStyle) {
|
|
117
136
|
heightRef.current = outerHeightStyle;
|
|
118
|
-
|
|
137
|
+
textarea.style.height = `${outerHeightStyle}px`;
|
|
119
138
|
}
|
|
120
|
-
|
|
139
|
+
textarea.style.overflow = textareaStyles.overflowing ? 'hidden' : '';
|
|
121
140
|
}, [calculateTextareaStyles]);
|
|
141
|
+
const frameRef = React.useRef(-1);
|
|
122
142
|
useEnhancedEffect(() => {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let rAF;
|
|
131
|
-
const rAFHandleResize = () => {
|
|
132
|
-
cancelAnimationFrame(rAF);
|
|
133
|
-
rAF = requestAnimationFrame(() => {
|
|
134
|
-
handleResize();
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
const debounceHandleResize = debounce(handleResize);
|
|
138
|
-
const input = inputRef.current;
|
|
139
|
-
const containerWindow = ownerWindow(input);
|
|
140
|
-
containerWindow.addEventListener('resize', debounceHandleResize);
|
|
143
|
+
const debouncedHandleResize = debounce(syncHeight);
|
|
144
|
+
const textarea = textareaRef == null ? void 0 : textareaRef.current;
|
|
145
|
+
if (!textarea) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const containerWindow = ownerWindow(textarea);
|
|
149
|
+
containerWindow.addEventListener('resize', debouncedHandleResize);
|
|
141
150
|
let resizeObserver;
|
|
142
151
|
if (typeof ResizeObserver !== 'undefined') {
|
|
143
|
-
resizeObserver = new ResizeObserver(
|
|
144
|
-
|
|
152
|
+
resizeObserver = new ResizeObserver(() => {
|
|
153
|
+
if (didHeightChange()) {
|
|
154
|
+
// avoid "ResizeObserver loop completed with undelivered notifications" error
|
|
155
|
+
// by temporarily unobserving the textarea element while manipulating the height
|
|
156
|
+
// and reobserving one frame later
|
|
157
|
+
resizeObserver.unobserve(textarea);
|
|
158
|
+
cancelAnimationFrame(frameRef.current);
|
|
159
|
+
syncHeight();
|
|
160
|
+
frameRef.current = requestAnimationFrame(() => {
|
|
161
|
+
resizeObserver.observe(textarea);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
resizeObserver.observe(textarea);
|
|
145
166
|
}
|
|
146
167
|
return () => {
|
|
147
|
-
|
|
148
|
-
cancelAnimationFrame(
|
|
149
|
-
containerWindow.removeEventListener('resize',
|
|
168
|
+
debouncedHandleResize.clear();
|
|
169
|
+
cancelAnimationFrame(frameRef.current);
|
|
170
|
+
containerWindow.removeEventListener('resize', debouncedHandleResize);
|
|
150
171
|
if (resizeObserver) {
|
|
151
172
|
resizeObserver.disconnect();
|
|
152
173
|
}
|
|
153
174
|
};
|
|
154
|
-
}, [calculateTextareaStyles, syncHeight]);
|
|
175
|
+
}, [calculateTextareaStyles, syncHeight, didHeightChange]);
|
|
155
176
|
useEnhancedEffect(() => {
|
|
156
177
|
syncHeight();
|
|
157
178
|
});
|
|
@@ -176,7 +197,7 @@ const TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize
|
|
|
176
197
|
"aria-hidden": true,
|
|
177
198
|
className: props.className,
|
|
178
199
|
readOnly: true,
|
|
179
|
-
ref:
|
|
200
|
+
ref: hiddenTextareaRef,
|
|
180
201
|
tabIndex: -1,
|
|
181
202
|
style: _extends({}, styles.shadow, style, {
|
|
182
203
|
paddingTop: 0,
|
package/index.js
CHANGED
|
@@ -594,67 +594,6 @@ var Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps,
|
|
|
594
594
|
var paperSlotProps = (_slotProps$paper = slotProps.paper) != null ? _slotProps$paper : componentsProps.paper;
|
|
595
595
|
var popperSlotProps = (_slotProps$popper = slotProps.popper) != null ? _slotProps$popper : componentsProps.popper;
|
|
596
596
|
var popupIndicatorSlotProps = (_slotProps$popupIndic = slotProps.popupIndicator) != null ? _slotProps$popupIndic : componentsProps.popupIndicator;
|
|
597
|
-
var renderAutocompletePopperChildren = function renderAutocompletePopperChildren(children) {
|
|
598
|
-
return /*#__PURE__*/_jsx(AutocompletePopper, _extends({
|
|
599
|
-
as: PopperComponent,
|
|
600
|
-
disablePortal: disablePortal,
|
|
601
|
-
style: {
|
|
602
|
-
width: anchorEl ? anchorEl.clientWidth : null
|
|
603
|
-
},
|
|
604
|
-
ownerState: ownerState,
|
|
605
|
-
role: "presentation",
|
|
606
|
-
anchorEl: anchorEl,
|
|
607
|
-
open: popupOpen
|
|
608
|
-
}, popperSlotProps, {
|
|
609
|
-
className: clsx(classes.popper, popperSlotProps == null ? void 0 : popperSlotProps.className),
|
|
610
|
-
children: /*#__PURE__*/_jsx(AutocompletePaper, _extends({
|
|
611
|
-
ownerState: ownerState,
|
|
612
|
-
as: PaperComponent
|
|
613
|
-
}, paperSlotProps, {
|
|
614
|
-
className: clsx(classes.paper, paperSlotProps == null ? void 0 : paperSlotProps.className),
|
|
615
|
-
children: children
|
|
616
|
-
}))
|
|
617
|
-
}));
|
|
618
|
-
};
|
|
619
|
-
var autocompletePopper = null;
|
|
620
|
-
if (groupedOptions.length > 0) {
|
|
621
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteListbox, _extends({
|
|
622
|
-
as: ListboxComponent,
|
|
623
|
-
className: classes.listbox,
|
|
624
|
-
ownerState: ownerState
|
|
625
|
-
}, otherListboxProps, ListboxProps, {
|
|
626
|
-
ref: combinedListboxRef,
|
|
627
|
-
children: groupedOptions.map(function (option, index) {
|
|
628
|
-
if (groupBy) {
|
|
629
|
-
return renderGroup({
|
|
630
|
-
key: option.key,
|
|
631
|
-
group: option.group,
|
|
632
|
-
children: option.options.map(function (option2, index2) {
|
|
633
|
-
return renderListOption(option2, option.index + index2);
|
|
634
|
-
})
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
return renderListOption(option, index);
|
|
638
|
-
})
|
|
639
|
-
})));
|
|
640
|
-
} else if (loading && groupedOptions.length === 0) {
|
|
641
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteLoading, {
|
|
642
|
-
className: classes.loading,
|
|
643
|
-
ownerState: ownerState,
|
|
644
|
-
children: loadingText
|
|
645
|
-
}));
|
|
646
|
-
} else if (groupedOptions.length === 0 && !freeSolo && !loading) {
|
|
647
|
-
autocompletePopper = renderAutocompletePopperChildren( /*#__PURE__*/_jsx(AutocompleteNoOptions, {
|
|
648
|
-
className: classes.noOptions,
|
|
649
|
-
ownerState: ownerState,
|
|
650
|
-
role: "presentation",
|
|
651
|
-
onMouseDown: function onMouseDown(event) {
|
|
652
|
-
// Prevent input blur when interacting with the "no options" content
|
|
653
|
-
event.preventDefault();
|
|
654
|
-
},
|
|
655
|
-
children: noOptionsText
|
|
656
|
-
}));
|
|
657
|
-
}
|
|
658
597
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
659
598
|
children: [/*#__PURE__*/_jsx(AutocompleteRoot, _extends({
|
|
660
599
|
ref: ref,
|
|
@@ -704,7 +643,57 @@ var Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps,
|
|
|
704
643
|
readOnly: readOnly
|
|
705
644
|
}, getInputProps())
|
|
706
645
|
})
|
|
707
|
-
})), anchorEl ?
|
|
646
|
+
})), anchorEl ? /*#__PURE__*/_jsx(AutocompletePopper, _extends({
|
|
647
|
+
as: PopperComponent,
|
|
648
|
+
disablePortal: disablePortal,
|
|
649
|
+
style: {
|
|
650
|
+
width: anchorEl ? anchorEl.clientWidth : null
|
|
651
|
+
},
|
|
652
|
+
ownerState: ownerState,
|
|
653
|
+
role: "presentation",
|
|
654
|
+
anchorEl: anchorEl,
|
|
655
|
+
open: popupOpen
|
|
656
|
+
}, popperSlotProps, {
|
|
657
|
+
className: clsx(classes.popper, popperSlotProps == null ? void 0 : popperSlotProps.className),
|
|
658
|
+
children: /*#__PURE__*/_jsxs(AutocompletePaper, _extends({
|
|
659
|
+
ownerState: ownerState,
|
|
660
|
+
as: PaperComponent
|
|
661
|
+
}, paperSlotProps, {
|
|
662
|
+
className: clsx(classes.paper, paperSlotProps == null ? void 0 : paperSlotProps.className),
|
|
663
|
+
children: [loading && groupedOptions.length === 0 ? /*#__PURE__*/_jsx(AutocompleteLoading, {
|
|
664
|
+
className: classes.loading,
|
|
665
|
+
ownerState: ownerState,
|
|
666
|
+
children: loadingText
|
|
667
|
+
}) : null, groupedOptions.length === 0 && !freeSolo && !loading ? /*#__PURE__*/_jsx(AutocompleteNoOptions, {
|
|
668
|
+
className: classes.noOptions,
|
|
669
|
+
ownerState: ownerState,
|
|
670
|
+
role: "presentation",
|
|
671
|
+
onMouseDown: function onMouseDown(event) {
|
|
672
|
+
// Prevent input blur when interacting with the "no options" content
|
|
673
|
+
event.preventDefault();
|
|
674
|
+
},
|
|
675
|
+
children: noOptionsText
|
|
676
|
+
}) : null, groupedOptions.length > 0 ? /*#__PURE__*/_jsx(AutocompleteListbox, _extends({
|
|
677
|
+
as: ListboxComponent,
|
|
678
|
+
className: classes.listbox,
|
|
679
|
+
ownerState: ownerState
|
|
680
|
+
}, otherListboxProps, ListboxProps, {
|
|
681
|
+
ref: combinedListboxRef,
|
|
682
|
+
children: groupedOptions.map(function (option, index) {
|
|
683
|
+
if (groupBy) {
|
|
684
|
+
return renderGroup({
|
|
685
|
+
key: option.key,
|
|
686
|
+
group: option.group,
|
|
687
|
+
children: option.options.map(function (option2, index2) {
|
|
688
|
+
return renderListOption(option2, option.index + index2);
|
|
689
|
+
})
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
return renderListOption(option, index);
|
|
693
|
+
})
|
|
694
|
+
})) : null]
|
|
695
|
+
}))
|
|
696
|
+
})) : null]
|
|
708
697
|
});
|
|
709
698
|
});
|
|
710
699
|
process.env.NODE_ENV !== "production" ? Autocomplete.propTypes /* remove-proptypes */ = {
|
|
@@ -4,7 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { unstable_debounce as debounce, unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
7
|
+
import { unstable_debounce as debounce, unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
10
|
function getStyleValue(value) {
|
|
@@ -25,8 +25,15 @@ var styles = {
|
|
|
25
25
|
transform: 'translateZ(0)'
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
function isObjectEmpty(object) {
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
for (var _ in object) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
28
35
|
function isEmpty(obj) {
|
|
29
|
-
return
|
|
36
|
+
return isObjectEmpty(obj) || obj.outerHeightStyle === 0 && !obj.overflowing;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
@@ -49,14 +56,18 @@ var TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize(p
|
|
|
49
56
|
other = _objectWithoutProperties(props, ["onChange", "maxRows", "minRows", "style", "value"]);
|
|
50
57
|
var _React$useRef = React.useRef(value != null),
|
|
51
58
|
isControlled = _React$useRef.current;
|
|
52
|
-
var
|
|
53
|
-
var handleRef = useForkRef(forwardedRef,
|
|
59
|
+
var textareaRef = React.useRef(null);
|
|
60
|
+
var handleRef = useForkRef(forwardedRef, textareaRef);
|
|
54
61
|
var heightRef = React.useRef(null);
|
|
55
|
-
var
|
|
62
|
+
var hiddenTextareaRef = React.useRef(null);
|
|
56
63
|
var calculateTextareaStyles = React.useCallback(function () {
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
|
|
64
|
+
var textarea = textareaRef.current;
|
|
65
|
+
var hiddenTextarea = hiddenTextareaRef.current;
|
|
66
|
+
if (!textarea || !hiddenTextarea) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
var containerWindow = ownerWindow(textarea);
|
|
70
|
+
var computedStyle = containerWindow.getComputedStyle(textarea);
|
|
60
71
|
|
|
61
72
|
// If input's width is shrunk and it's not visible, don't sync height.
|
|
62
73
|
if (computedStyle.width === '0px') {
|
|
@@ -65,25 +76,24 @@ var TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize(p
|
|
|
65
76
|
overflowing: false
|
|
66
77
|
};
|
|
67
78
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (inputShallow.value.slice(-1) === '\n') {
|
|
79
|
+
hiddenTextarea.style.width = computedStyle.width;
|
|
80
|
+
hiddenTextarea.value = textarea.value || props.placeholder || 'x';
|
|
81
|
+
if (hiddenTextarea.value.slice(-1) === '\n') {
|
|
72
82
|
// Certain fonts which overflow the line height will cause the textarea
|
|
73
83
|
// to report a different scrollHeight depending on whether the last line
|
|
74
84
|
// is empty. Make it non-empty to avoid this issue.
|
|
75
|
-
|
|
85
|
+
hiddenTextarea.value += ' ';
|
|
76
86
|
}
|
|
77
87
|
var boxSizing = computedStyle.boxSizing;
|
|
78
88
|
var padding = getStyleValue(computedStyle.paddingBottom) + getStyleValue(computedStyle.paddingTop);
|
|
79
89
|
var border = getStyleValue(computedStyle.borderBottomWidth) + getStyleValue(computedStyle.borderTopWidth);
|
|
80
90
|
|
|
81
91
|
// The height of the inner content
|
|
82
|
-
var innerHeight =
|
|
92
|
+
var innerHeight = hiddenTextarea.scrollHeight;
|
|
83
93
|
|
|
84
94
|
// Measure height of a textarea with a single row
|
|
85
|
-
|
|
86
|
-
var singleRowHeight =
|
|
95
|
+
hiddenTextarea.value = 'x';
|
|
96
|
+
var singleRowHeight = hiddenTextarea.scrollHeight;
|
|
87
97
|
|
|
88
98
|
// The height of the outer content
|
|
89
99
|
var outerHeight = innerHeight;
|
|
@@ -103,52 +113,63 @@ var TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize(p
|
|
|
103
113
|
overflowing: overflowing
|
|
104
114
|
};
|
|
105
115
|
}, [maxRows, minRows, props.placeholder]);
|
|
116
|
+
var didHeightChange = useEventCallback(function () {
|
|
117
|
+
var textarea = textareaRef.current;
|
|
118
|
+
var textareaStyles = calculateTextareaStyles();
|
|
119
|
+
if (!textarea || !textareaStyles || isEmpty(textareaStyles)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
var outerHeightStyle = textareaStyles.outerHeightStyle;
|
|
123
|
+
return heightRef.current != null && heightRef.current !== outerHeightStyle;
|
|
124
|
+
});
|
|
106
125
|
var syncHeight = React.useCallback(function () {
|
|
126
|
+
var textarea = textareaRef.current;
|
|
107
127
|
var textareaStyles = calculateTextareaStyles();
|
|
108
|
-
if (isEmpty(textareaStyles)) {
|
|
128
|
+
if (!textarea || !textareaStyles || isEmpty(textareaStyles)) {
|
|
109
129
|
return;
|
|
110
130
|
}
|
|
111
131
|
var outerHeightStyle = textareaStyles.outerHeightStyle;
|
|
112
|
-
var input = inputRef.current;
|
|
113
132
|
if (heightRef.current !== outerHeightStyle) {
|
|
114
133
|
heightRef.current = outerHeightStyle;
|
|
115
|
-
|
|
134
|
+
textarea.style.height = "".concat(outerHeightStyle, "px");
|
|
116
135
|
}
|
|
117
|
-
|
|
136
|
+
textarea.style.overflow = textareaStyles.overflowing ? 'hidden' : '';
|
|
118
137
|
}, [calculateTextareaStyles]);
|
|
138
|
+
var frameRef = React.useRef(-1);
|
|
119
139
|
useEnhancedEffect(function () {
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var rAF;
|
|
128
|
-
var rAFHandleResize = function rAFHandleResize() {
|
|
129
|
-
cancelAnimationFrame(rAF);
|
|
130
|
-
rAF = requestAnimationFrame(function () {
|
|
131
|
-
handleResize();
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
var debounceHandleResize = debounce(handleResize);
|
|
135
|
-
var input = inputRef.current;
|
|
136
|
-
var containerWindow = ownerWindow(input);
|
|
137
|
-
containerWindow.addEventListener('resize', debounceHandleResize);
|
|
140
|
+
var debouncedHandleResize = debounce(syncHeight);
|
|
141
|
+
var textarea = textareaRef == null ? void 0 : textareaRef.current;
|
|
142
|
+
if (!textarea) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
var containerWindow = ownerWindow(textarea);
|
|
146
|
+
containerWindow.addEventListener('resize', debouncedHandleResize);
|
|
138
147
|
var resizeObserver;
|
|
139
148
|
if (typeof ResizeObserver !== 'undefined') {
|
|
140
|
-
resizeObserver = new ResizeObserver(
|
|
141
|
-
|
|
149
|
+
resizeObserver = new ResizeObserver(function () {
|
|
150
|
+
if (didHeightChange()) {
|
|
151
|
+
// avoid "ResizeObserver loop completed with undelivered notifications" error
|
|
152
|
+
// by temporarily unobserving the textarea element while manipulating the height
|
|
153
|
+
// and reobserving one frame later
|
|
154
|
+
resizeObserver.unobserve(textarea);
|
|
155
|
+
cancelAnimationFrame(frameRef.current);
|
|
156
|
+
syncHeight();
|
|
157
|
+
frameRef.current = requestAnimationFrame(function () {
|
|
158
|
+
resizeObserver.observe(textarea);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
resizeObserver.observe(textarea);
|
|
142
163
|
}
|
|
143
164
|
return function () {
|
|
144
|
-
|
|
145
|
-
cancelAnimationFrame(
|
|
146
|
-
containerWindow.removeEventListener('resize',
|
|
165
|
+
debouncedHandleResize.clear();
|
|
166
|
+
cancelAnimationFrame(frameRef.current);
|
|
167
|
+
containerWindow.removeEventListener('resize', debouncedHandleResize);
|
|
147
168
|
if (resizeObserver) {
|
|
148
169
|
resizeObserver.disconnect();
|
|
149
170
|
}
|
|
150
171
|
};
|
|
151
|
-
}, [calculateTextareaStyles, syncHeight]);
|
|
172
|
+
}, [calculateTextareaStyles, syncHeight, didHeightChange]);
|
|
152
173
|
useEnhancedEffect(function () {
|
|
153
174
|
syncHeight();
|
|
154
175
|
});
|
|
@@ -173,7 +194,7 @@ var TextareaAutosize = /*#__PURE__*/React.forwardRef(function TextareaAutosize(p
|
|
|
173
194
|
"aria-hidden": true,
|
|
174
195
|
className: props.className,
|
|
175
196
|
readOnly: true,
|
|
176
|
-
ref:
|
|
197
|
+
ref: hiddenTextareaRef,
|
|
177
198
|
tabIndex: -1,
|
|
178
199
|
style: _extends({}, styles.shadow, style, {
|
|
179
200
|
paddingTop: 0,
|
package/legacy/index.js
CHANGED