UNPKG

41.5 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9Object.defineProperty(exports, "createFilterOptions", {
10 enumerable: true,
11 get: function () {
12 return _useAutocomplete.createFilterOptions;
13 }
14});
15exports.default = void 0;
16var React = _interopRequireWildcard(require("react"));
17var _propTypes = _interopRequireDefault(require("prop-types"));
18var _clsx = _interopRequireDefault(require("clsx"));
19var _integerPropType = _interopRequireDefault(require("@mui/utils/integerPropType"));
20var _chainPropTypes = _interopRequireDefault(require("@mui/utils/chainPropTypes"));
21var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
22var _colorManipulator = require("@mui/system/colorManipulator");
23var _useAutocomplete = _interopRequireWildcard(require("../useAutocomplete"));
24var _Popper = _interopRequireDefault(require("../Popper"));
25var _ListSubheader = _interopRequireDefault(require("../ListSubheader"));
26var _Paper = _interopRequireDefault(require("../Paper"));
27var _IconButton = _interopRequireDefault(require("../IconButton"));
28var _Chip = _interopRequireDefault(require("../Chip"));
29var _inputClasses = _interopRequireDefault(require("../Input/inputClasses"));
30var _inputBaseClasses = _interopRequireDefault(require("../InputBase/inputBaseClasses"));
31var _outlinedInputClasses = _interopRequireDefault(require("../OutlinedInput/outlinedInputClasses"));
32var _filledInputClasses = _interopRequireDefault(require("../FilledInput/filledInputClasses"));
33var _Close = _interopRequireDefault(require("../internal/svg-icons/Close"));
34var _ArrowDropDown = _interopRequireDefault(require("../internal/svg-icons/ArrowDropDown"));
35var _zeroStyled = require("../zero-styled");
36var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
37var _DefaultPropsProvider = require("../DefaultPropsProvider");
38var _autocompleteClasses = _interopRequireWildcard(require("./autocompleteClasses"));
39var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
40var _useSlot = _interopRequireDefault(require("../utils/useSlot"));
41var _jsxRuntime = require("react/jsx-runtime");
42var _ClearIcon, _ArrowDropDownIcon;
43const useUtilityClasses = ownerState => {
44 const {
45 classes,
46 disablePortal,
47 expanded,
48 focused,
49 fullWidth,
50 hasClearIcon,
51 hasPopupIcon,
52 inputFocused,
53 popupOpen,
54 size
55 } = ownerState;
56 const slots = {
57 root: ['root', expanded && 'expanded', focused && 'focused', fullWidth && 'fullWidth', hasClearIcon && 'hasClearIcon', hasPopupIcon && 'hasPopupIcon'],
58 inputRoot: ['inputRoot'],
59 input: ['input', inputFocused && 'inputFocused'],
60 tag: ['tag', `tagSize${(0, _capitalize.default)(size)}`],
61 endAdornment: ['endAdornment'],
62 clearIndicator: ['clearIndicator'],
63 popupIndicator: ['popupIndicator', popupOpen && 'popupIndicatorOpen'],
64 popper: ['popper', disablePortal && 'popperDisablePortal'],
65 paper: ['paper'],
66 listbox: ['listbox'],
67 loading: ['loading'],
68 noOptions: ['noOptions'],
69 option: ['option'],
70 groupLabel: ['groupLabel'],
71 groupUl: ['groupUl']
72 };
73 return (0, _composeClasses.default)(slots, _autocompleteClasses.getAutocompleteUtilityClass, classes);
74};
75const AutocompleteRoot = (0, _zeroStyled.styled)('div', {
76 name: 'MuiAutocomplete',
77 slot: 'Root',
78 overridesResolver: (props, styles) => {
79 const {
80 ownerState
81 } = props;
82 const {
83 fullWidth,
84 hasClearIcon,
85 hasPopupIcon,
86 inputFocused,
87 size
88 } = ownerState;
89 return [{
90 [`& .${_autocompleteClasses.default.tag}`]: styles.tag
91 }, {
92 [`& .${_autocompleteClasses.default.tag}`]: styles[`tagSize${(0, _capitalize.default)(size)}`]
93 }, {
94 [`& .${_autocompleteClasses.default.inputRoot}`]: styles.inputRoot
95 }, {
96 [`& .${_autocompleteClasses.default.input}`]: styles.input
97 }, {
98 [`& .${_autocompleteClasses.default.input}`]: inputFocused && styles.inputFocused
99 }, styles.root, fullWidth && styles.fullWidth, hasPopupIcon && styles.hasPopupIcon, hasClearIcon && styles.hasClearIcon];
100 }
101})({
102 [`&.${_autocompleteClasses.default.focused} .${_autocompleteClasses.default.clearIndicator}`]: {
103 visibility: 'visible'
104 },
105 /* Avoid double tap issue on iOS */
106 '@media (pointer: fine)': {
107 [`&:hover .${_autocompleteClasses.default.clearIndicator}`]: {
108 visibility: 'visible'
109 }
110 },
111 [`& .${_autocompleteClasses.default.tag}`]: {
112 margin: 3,
113 maxWidth: 'calc(100% - 6px)'
114 },
115 [`& .${_autocompleteClasses.default.inputRoot}`]: {
116 [`.${_autocompleteClasses.default.hasPopupIcon}&, .${_autocompleteClasses.default.hasClearIcon}&`]: {
117 paddingRight: 26 + 4
118 },
119 [`.${_autocompleteClasses.default.hasPopupIcon}.${_autocompleteClasses.default.hasClearIcon}&`]: {
120 paddingRight: 52 + 4
121 },
122 [`& .${_autocompleteClasses.default.input}`]: {
123 width: 0,
124 minWidth: 30
125 }
126 },
127 [`& .${_inputClasses.default.root}`]: {
128 paddingBottom: 1,
129 '& .MuiInput-input': {
130 padding: '4px 4px 4px 0px'
131 }
132 },
133 [`& .${_inputClasses.default.root}.${_inputBaseClasses.default.sizeSmall}`]: {
134 [`& .${_inputClasses.default.input}`]: {
135 padding: '2px 4px 3px 0'
136 }
137 },
138 [`& .${_outlinedInputClasses.default.root}`]: {
139 padding: 9,
140 [`.${_autocompleteClasses.default.hasPopupIcon}&, .${_autocompleteClasses.default.hasClearIcon}&`]: {
141 paddingRight: 26 + 4 + 9
142 },
143 [`.${_autocompleteClasses.default.hasPopupIcon}.${_autocompleteClasses.default.hasClearIcon}&`]: {
144 paddingRight: 52 + 4 + 9
145 },
146 [`& .${_autocompleteClasses.default.input}`]: {
147 padding: '7.5px 4px 7.5px 5px'
148 },
149 [`& .${_autocompleteClasses.default.endAdornment}`]: {
150 right: 9
151 }
152 },
153 [`& .${_outlinedInputClasses.default.root}.${_inputBaseClasses.default.sizeSmall}`]: {
154 // Don't specify paddingRight, as it overrides the default value set when there is only
155 // one of the popup or clear icon as the specificity is equal so the latter one wins
156 paddingTop: 6,
157 paddingBottom: 6,
158 paddingLeft: 6,
159 [`& .${_autocompleteClasses.default.input}`]: {
160 padding: '2.5px 4px 2.5px 8px'
161 }
162 },
163 [`& .${_filledInputClasses.default.root}`]: {
164 paddingTop: 19,
165 paddingLeft: 8,
166 [`.${_autocompleteClasses.default.hasPopupIcon}&, .${_autocompleteClasses.default.hasClearIcon}&`]: {
167 paddingRight: 26 + 4 + 9
168 },
169 [`.${_autocompleteClasses.default.hasPopupIcon}.${_autocompleteClasses.default.hasClearIcon}&`]: {
170 paddingRight: 52 + 4 + 9
171 },
172 [`& .${_filledInputClasses.default.input}`]: {
173 padding: '7px 4px'
174 },
175 [`& .${_autocompleteClasses.default.endAdornment}`]: {
176 right: 9
177 }
178 },
179 [`& .${_filledInputClasses.default.root}.${_inputBaseClasses.default.sizeSmall}`]: {
180 paddingBottom: 1,
181 [`& .${_filledInputClasses.default.input}`]: {
182 padding: '2.5px 4px'
183 }
184 },
185 [`& .${_inputBaseClasses.default.hiddenLabel}`]: {
186 paddingTop: 8
187 },
188 [`& .${_filledInputClasses.default.root}.${_inputBaseClasses.default.hiddenLabel}`]: {
189 paddingTop: 0,
190 paddingBottom: 0,
191 [`& .${_autocompleteClasses.default.input}`]: {
192 paddingTop: 16,
193 paddingBottom: 17
194 }
195 },
196 [`& .${_filledInputClasses.default.root}.${_inputBaseClasses.default.hiddenLabel}.${_inputBaseClasses.default.sizeSmall}`]: {
197 [`& .${_autocompleteClasses.default.input}`]: {
198 paddingTop: 8,
199 paddingBottom: 9
200 }
201 },
202 [`& .${_autocompleteClasses.default.input}`]: {
203 flexGrow: 1,
204 textOverflow: 'ellipsis',
205 opacity: 0
206 },
207 variants: [{
208 props: {
209 fullWidth: true
210 },
211 style: {
212 width: '100%'
213 }
214 }, {
215 props: {
216 size: 'small'
217 },
218 style: {
219 [`& .${_autocompleteClasses.default.tag}`]: {
220 margin: 2,
221 maxWidth: 'calc(100% - 4px)'
222 }
223 }
224 }, {
225 props: {
226 inputFocused: true
227 },
228 style: {
229 [`& .${_autocompleteClasses.default.input}`]: {
230 opacity: 1
231 }
232 }
233 }, {
234 props: {
235 multiple: true
236 },
237 style: {
238 [`& .${_autocompleteClasses.default.inputRoot}`]: {
239 flexWrap: 'wrap'
240 }
241 }
242 }]
243});
244const AutocompleteEndAdornment = (0, _zeroStyled.styled)('div', {
245 name: 'MuiAutocomplete',
246 slot: 'EndAdornment',
247 overridesResolver: (props, styles) => styles.endAdornment
248})({
249 // We use a position absolute to support wrapping tags.
250 position: 'absolute',
251 right: 0,
252 top: '50%',
253 transform: 'translate(0, -50%)'
254});
255const AutocompleteClearIndicator = (0, _zeroStyled.styled)(_IconButton.default, {
256 name: 'MuiAutocomplete',
257 slot: 'ClearIndicator',
258 overridesResolver: (props, styles) => styles.clearIndicator
259})({
260 marginRight: -2,
261 padding: 4,
262 visibility: 'hidden'
263});
264const AutocompletePopupIndicator = (0, _zeroStyled.styled)(_IconButton.default, {
265 name: 'MuiAutocomplete',
266 slot: 'PopupIndicator',
267 overridesResolver: ({
268 ownerState
269 }, styles) => ({
270 ...styles.popupIndicator,
271 ...(ownerState.popupOpen && styles.popupIndicatorOpen)
272 })
273})({
274 padding: 2,
275 marginRight: -2,
276 variants: [{
277 props: {
278 popupOpen: true
279 },
280 style: {
281 transform: 'rotate(180deg)'
282 }
283 }]
284});
285const AutocompletePopper = (0, _zeroStyled.styled)(_Popper.default, {
286 name: 'MuiAutocomplete',
287 slot: 'Popper',
288 overridesResolver: (props, styles) => {
289 const {
290 ownerState
291 } = props;
292 return [{
293 [`& .${_autocompleteClasses.default.option}`]: styles.option
294 }, styles.popper, ownerState.disablePortal && styles.popperDisablePortal];
295 }
296})((0, _memoTheme.default)(({
297 theme
298}) => ({
299 zIndex: (theme.vars || theme).zIndex.modal,
300 variants: [{
301 props: {
302 disablePortal: true
303 },
304 style: {
305 position: 'absolute'
306 }
307 }]
308})));
309const AutocompletePaper = (0, _zeroStyled.styled)(_Paper.default, {
310 name: 'MuiAutocomplete',
311 slot: 'Paper',
312 overridesResolver: (props, styles) => styles.paper
313})((0, _memoTheme.default)(({
314 theme
315}) => ({
316 ...theme.typography.body1,
317 overflow: 'auto'
318})));
319const AutocompleteLoading = (0, _zeroStyled.styled)('div', {
320 name: 'MuiAutocomplete',
321 slot: 'Loading',
322 overridesResolver: (props, styles) => styles.loading
323})((0, _memoTheme.default)(({
324 theme
325}) => ({
326 color: (theme.vars || theme).palette.text.secondary,
327 padding: '14px 16px'
328})));
329const AutocompleteNoOptions = (0, _zeroStyled.styled)('div', {
330 name: 'MuiAutocomplete',
331 slot: 'NoOptions',
332 overridesResolver: (props, styles) => styles.noOptions
333})((0, _memoTheme.default)(({
334 theme
335}) => ({
336 color: (theme.vars || theme).palette.text.secondary,
337 padding: '14px 16px'
338})));
339const AutocompleteListbox = (0, _zeroStyled.styled)('div', {
340 name: 'MuiAutocomplete',
341 slot: 'Listbox',
342 overridesResolver: (props, styles) => styles.listbox
343})((0, _memoTheme.default)(({
344 theme
345}) => ({
346 listStyle: 'none',
347 margin: 0,
348 padding: '8px 0',
349 maxHeight: '40vh',
350 overflow: 'auto',
351 position: 'relative',
352 [`& .${_autocompleteClasses.default.option}`]: {
353 minHeight: 48,
354 display: 'flex',
355 overflow: 'hidden',
356 justifyContent: 'flex-start',
357 alignItems: 'center',
358 cursor: 'pointer',
359 paddingTop: 6,
360 boxSizing: 'border-box',
361 outline: '0',
362 WebkitTapHighlightColor: 'transparent',
363 paddingBottom: 6,
364 paddingLeft: 16,
365 paddingRight: 16,
366 [theme.breakpoints.up('sm')]: {
367 minHeight: 'auto'
368 },
369 [`&.${_autocompleteClasses.default.focused}`]: {
370 backgroundColor: (theme.vars || theme).palette.action.hover,
371 // Reset on touch devices, it doesn't add specificity
372 '@media (hover: none)': {
373 backgroundColor: 'transparent'
374 }
375 },
376 '&[aria-disabled="true"]': {
377 opacity: (theme.vars || theme).palette.action.disabledOpacity,
378 pointerEvents: 'none'
379 },
380 [`&.${_autocompleteClasses.default.focusVisible}`]: {
381 backgroundColor: (theme.vars || theme).palette.action.focus
382 },
383 '&[aria-selected="true"]': {
384 backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : (0, _colorManipulator.alpha)(theme.palette.primary.main, theme.palette.action.selectedOpacity),
385 [`&.${_autocompleteClasses.default.focused}`]: {
386 backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` : (0, _colorManipulator.alpha)(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
387 // Reset on touch devices, it doesn't add specificity
388 '@media (hover: none)': {
389 backgroundColor: (theme.vars || theme).palette.action.selected
390 }
391 },
392 [`&.${_autocompleteClasses.default.focusVisible}`]: {
393 backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.focusOpacity}))` : (0, _colorManipulator.alpha)(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
394 }
395 }
396 }
397})));
398const AutocompleteGroupLabel = (0, _zeroStyled.styled)(_ListSubheader.default, {
399 name: 'MuiAutocomplete',
400 slot: 'GroupLabel',
401 overridesResolver: (props, styles) => styles.groupLabel
402})((0, _memoTheme.default)(({
403 theme
404}) => ({
405 backgroundColor: (theme.vars || theme).palette.background.paper,
406 top: -8
407})));
408const AutocompleteGroupUl = (0, _zeroStyled.styled)('ul', {
409 name: 'MuiAutocomplete',
410 slot: 'GroupUl',
411 overridesResolver: (props, styles) => styles.groupUl
412})({
413 padding: 0,
414 [`& .${_autocompleteClasses.default.option}`]: {
415 paddingLeft: 24
416 }
417});
418const Autocomplete = /*#__PURE__*/React.forwardRef(function Autocomplete(inProps, ref) {
419 const props = (0, _DefaultPropsProvider.useDefaultProps)({
420 props: inProps,
421 name: 'MuiAutocomplete'
422 });
423
424 /* eslint-disable @typescript-eslint/no-unused-vars */
425 const {
426 autoComplete = false,
427 autoHighlight = false,
428 autoSelect = false,
429 blurOnSelect = false,
430 ChipProps: ChipPropsProp,
431 className,
432 clearIcon = _ClearIcon || (_ClearIcon = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Close.default, {
433 fontSize: "small"
434 })),
435 clearOnBlur = !props.freeSolo,
436 clearOnEscape = false,
437 clearText = 'Clear',
438 closeText = 'Close',
439 componentsProps,
440 defaultValue = props.multiple ? [] : null,
441 disableClearable = false,
442 disableCloseOnSelect = false,
443 disabled = false,
444 disabledItemsFocusable = false,
445 disableListWrap = false,
446 disablePortal = false,
447 filterOptions,
448 filterSelectedOptions = false,
449 forcePopupIcon = 'auto',
450 freeSolo = false,
451 fullWidth = false,
452 getLimitTagsText = more => `+${more}`,
453 getOptionDisabled,
454 getOptionKey,
455 getOptionLabel: getOptionLabelProp,
456 isOptionEqualToValue,
457 groupBy,
458 handleHomeEndKeys = !props.freeSolo,
459 id: idProp,
460 includeInputInList = false,
461 inputValue: inputValueProp,
462 limitTags = -1,
463 ListboxComponent: ListboxComponentProp,
464 ListboxProps: ListboxPropsProp,
465 loading = false,
466 loadingText = 'Loading…',
467 multiple = false,
468 noOptionsText = 'No options',
469 onChange,
470 onClose,
471 onHighlightChange,
472 onInputChange,
473 onOpen,
474 open,
475 openOnFocus = false,
476 openText = 'Open',
477 options,
478 PaperComponent: PaperComponentProp,
479 PopperComponent: PopperComponentProp,
480 popupIcon = _ArrowDropDownIcon || (_ArrowDropDownIcon = /*#__PURE__*/(0, _jsxRuntime.jsx)(_ArrowDropDown.default, {})),
481 readOnly = false,
482 renderGroup: renderGroupProp,
483 renderInput,
484 renderOption: renderOptionProp,
485 renderTags,
486 selectOnFocus = !props.freeSolo,
487 size = 'medium',
488 slots = {},
489 slotProps = {},
490 value: valueProp,
491 ...other
492 } = props;
493 /* eslint-enable @typescript-eslint/no-unused-vars */
494
495 const {
496 getRootProps,
497 getInputProps,
498 getInputLabelProps,
499 getPopupIndicatorProps,
500 getClearProps,
501 getTagProps,
502 getListboxProps,
503 getOptionProps,
504 value,
505 dirty,
506 expanded,
507 id,
508 popupOpen,
509 focused,
510 focusedTag,
511 anchorEl,
512 setAnchorEl,
513 inputValue,
514 groupedOptions
515 } = (0, _useAutocomplete.default)({
516 ...props,
517 componentName: 'Autocomplete'
518 });
519 const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
520 const hasPopupIcon = (!freeSolo || forcePopupIcon === true) && forcePopupIcon !== false;
521 const {
522 onMouseDown: handleInputMouseDown
523 } = getInputProps();
524 const {
525 ref: listboxRef,
526 ...otherListboxProps
527 } = getListboxProps();
528 const defaultGetOptionLabel = option => option.label ?? option;
529 const getOptionLabel = getOptionLabelProp || defaultGetOptionLabel;
530
531 // If you modify this, make sure to keep the `AutocompleteOwnerState` type in sync.
532 const ownerState = {
533 ...props,
534 disablePortal,
535 expanded,
536 focused,
537 fullWidth,
538 getOptionLabel,
539 hasClearIcon,
540 hasPopupIcon,
541 inputFocused: focusedTag === -1,
542 popupOpen,
543 size
544 };
545 const classes = useUtilityClasses(ownerState);
546 const externalForwardedProps = {
547 slots: {
548 paper: PaperComponentProp,
549 popper: PopperComponentProp,
550 ...slots
551 },
552 slotProps: {
553 chip: ChipPropsProp,
554 listbox: ListboxPropsProp,
555 ...componentsProps,
556 ...slotProps
557 }
558 };
559 const [ListboxSlot, listboxProps] = (0, _useSlot.default)('listbox', {
560 elementType: AutocompleteListbox,
561 externalForwardedProps,
562 ownerState,
563 className: classes.listbox,
564 additionalProps: otherListboxProps,
565 ref: listboxRef
566 });
567 const [PaperSlot, paperProps] = (0, _useSlot.default)('paper', {
568 elementType: _Paper.default,
569 externalForwardedProps,
570 ownerState,
571 className: classes.paper
572 });
573 const [PopperSlot, popperProps] = (0, _useSlot.default)('popper', {
574 elementType: _Popper.default,
575 externalForwardedProps,
576 ownerState,
577 className: classes.popper,
578 additionalProps: {
579 disablePortal,
580 style: {
581 width: anchorEl ? anchorEl.clientWidth : null
582 },
583 role: 'presentation',
584 anchorEl,
585 open: popupOpen
586 }
587 });
588 let startAdornment;
589 if (multiple && value.length > 0) {
590 const getCustomizedTagProps = params => ({
591 className: classes.tag,
592 disabled,
593 ...getTagProps(params)
594 });
595 if (renderTags) {
596 startAdornment = renderTags(value, getCustomizedTagProps, ownerState);
597 } else {
598 startAdornment = value.map((option, index) => {
599 const {
600 key,
601 ...customTagProps
602 } = getCustomizedTagProps({
603 index
604 });
605 return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
606 label: getOptionLabel(option),
607 size: size,
608 ...customTagProps,
609 ...externalForwardedProps.slotProps.chip
610 }, key);
611 });
612 }
613 }
614 if (limitTags > -1 && Array.isArray(startAdornment)) {
615 const more = startAdornment.length - limitTags;
616 if (!focused && more > 0) {
617 startAdornment = startAdornment.splice(0, limitTags);
618 startAdornment.push(/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
619 className: classes.tag,
620 children: getLimitTagsText(more)
621 }, startAdornment.length));
622 }
623 }
624 const defaultRenderGroup = params => /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
625 children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteGroupLabel, {
626 className: classes.groupLabel,
627 ownerState: ownerState,
628 component: "div",
629 children: params.group
630 }), /*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteGroupUl, {
631 className: classes.groupUl,
632 ownerState: ownerState,
633 children: params.children
634 })]
635 }, params.key);
636 const renderGroup = renderGroupProp || defaultRenderGroup;
637 const defaultRenderOption = (props2, option) => {
638 // Need to clearly apply key because of https://github.com/vercel/next.js/issues/55642
639 const {
640 key,
641 ...otherProps
642 } = props2;
643 return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
644 ...otherProps,
645 children: getOptionLabel(option)
646 }, key);
647 };
648 const renderOption = renderOptionProp || defaultRenderOption;
649 const renderListOption = (option, index) => {
650 const optionProps = getOptionProps({
651 option,
652 index
653 });
654 return renderOption({
655 ...optionProps,
656 className: classes.option
657 }, option, {
658 selected: optionProps['aria-selected'],
659 index,
660 inputValue
661 }, ownerState);
662 };
663 const clearIndicatorSlotProps = externalForwardedProps.slotProps.clearIndicator;
664 const popupIndicatorSlotProps = externalForwardedProps.slotProps.popupIndicator;
665 const renderAutocompletePopperChildren = children => /*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompletePopper, {
666 as: PopperSlot,
667 ...popperProps,
668 children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompletePaper, {
669 as: PaperSlot,
670 ...paperProps,
671 children: children
672 })
673 });
674 let autocompletePopper = null;
675 if (groupedOptions.length > 0) {
676 autocompletePopper = renderAutocompletePopperChildren(
677 /*#__PURE__*/
678 // TODO v7: remove `as` prop and move ListboxComponentProp to externalForwardedProps or remove ListboxComponentProp entirely
679 // https://github.com/mui/material-ui/pull/43994#issuecomment-2401945800
680 (0, _jsxRuntime.jsx)(ListboxSlot, {
681 as: ListboxComponentProp,
682 ...listboxProps,
683 children: groupedOptions.map((option, index) => {
684 if (groupBy) {
685 return renderGroup({
686 key: option.key,
687 group: option.group,
688 children: option.options.map((option2, index2) => renderListOption(option2, option.index + index2))
689 });
690 }
691 return renderListOption(option, index);
692 })
693 }));
694 } else if (loading && groupedOptions.length === 0) {
695 autocompletePopper = renderAutocompletePopperChildren(/*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteLoading, {
696 className: classes.loading,
697 ownerState: ownerState,
698 children: loadingText
699 }));
700 } else if (groupedOptions.length === 0 && !freeSolo && !loading) {
701 autocompletePopper = renderAutocompletePopperChildren(/*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteNoOptions, {
702 className: classes.noOptions,
703 ownerState: ownerState,
704 role: "presentation",
705 onMouseDown: event => {
706 // Prevent input blur when interacting with the "no options" content
707 event.preventDefault();
708 },
709 children: noOptionsText
710 }));
711 }
712 return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
713 children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteRoot, {
714 ref: ref,
715 className: (0, _clsx.default)(classes.root, className),
716 ownerState: ownerState,
717 ...getRootProps(other),
718 children: renderInput({
719 id,
720 disabled,
721 fullWidth: true,
722 size: size === 'small' ? 'small' : undefined,
723 InputLabelProps: getInputLabelProps(),
724 InputProps: {
725 ref: setAnchorEl,
726 className: classes.inputRoot,
727 startAdornment,
728 onMouseDown: event => {
729 if (event.target === event.currentTarget) {
730 handleInputMouseDown(event);
731 }
732 },
733 ...((hasClearIcon || hasPopupIcon) && {
734 endAdornment: /*#__PURE__*/(0, _jsxRuntime.jsxs)(AutocompleteEndAdornment, {
735 className: classes.endAdornment,
736 ownerState: ownerState,
737 children: [hasClearIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompleteClearIndicator, {
738 ...getClearProps(),
739 "aria-label": clearText,
740 title: clearText,
741 ownerState: ownerState,
742 ...clearIndicatorSlotProps,
743 className: (0, _clsx.default)(classes.clearIndicator, clearIndicatorSlotProps?.className),
744 children: clearIcon
745 }) : null, hasPopupIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(AutocompletePopupIndicator, {
746 ...getPopupIndicatorProps(),
747 disabled: disabled,
748 "aria-label": popupOpen ? closeText : openText,
749 title: popupOpen ? closeText : openText,
750 ownerState: ownerState,
751 ...popupIndicatorSlotProps,
752 className: (0, _clsx.default)(classes.popupIndicator, popupIndicatorSlotProps?.className),
753 children: popupIcon
754 }) : null]
755 })
756 })
757 },
758 inputProps: {
759 className: classes.input,
760 disabled,
761 readOnly,
762 ...getInputProps()
763 }
764 })
765 }), anchorEl ? autocompletePopper : null]
766 });
767});
768process.env.NODE_ENV !== "production" ? Autocomplete.propTypes /* remove-proptypes */ = {
769 // ┌────────────────────────────── Warning ──────────────────────────────┐
770 // │ These PropTypes are generated from the TypeScript type definitions. │
771 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
772 // └─────────────────────────────────────────────────────────────────────┘
773 /**
774 * If `true`, the portion of the selected suggestion that the user hasn't typed,
775 * known as the completion string, appears inline after the input cursor in the textbox.
776 * The inline completion string is visually highlighted and has a selected state.
777 * @default false
778 */
779 autoComplete: _propTypes.default.bool,
780 /**
781 * If `true`, the first option is automatically highlighted.
782 * @default false
783 */
784 autoHighlight: _propTypes.default.bool,
785 /**
786 * If `true`, the selected option becomes the value of the input
787 * when the Autocomplete loses focus unless the user chooses
788 * a different option or changes the character string in the input.
789 *
790 * When using the `freeSolo` mode, the typed value will be the input value
791 * if the Autocomplete loses focus without highlighting an option.
792 * @default false
793 */
794 autoSelect: _propTypes.default.bool,
795 /**
796 * Control if the input should be blurred when an option is selected:
797 *
798 * - `false` the input is not blurred.
799 * - `true` the input is always blurred.
800 * - `touch` the input is blurred after a touch event.
801 * - `mouse` the input is blurred after a mouse event.
802 * @default false
803 */
804 blurOnSelect: _propTypes.default.oneOfType([_propTypes.default.oneOf(['mouse', 'touch']), _propTypes.default.bool]),
805 /**
806 * Props applied to the [`Chip`](https://mui.com/material-ui/api/chip/) element.
807 */
808 ChipProps: _propTypes.default.object,
809 /**
810 * Override or extend the styles applied to the component.
811 */
812 classes: _propTypes.default.object,
813 /**
814 * @ignore
815 */
816 className: _propTypes.default.string,
817 /**
818 * The icon to display in place of the default clear icon.
819 * @default <ClearIcon fontSize="small" />
820 */
821 clearIcon: _propTypes.default.node,
822 /**
823 * If `true`, the input's text is cleared on blur if no value is selected.
824 *
825 * Set it to `true` if you want to help the user enter a new value.
826 * Set it to `false` if you want to help the user resume their search.
827 * @default !props.freeSolo
828 */
829 clearOnBlur: _propTypes.default.bool,
830 /**
831 * If `true`, clear all values when the user presses escape and the popup is closed.
832 * @default false
833 */
834 clearOnEscape: _propTypes.default.bool,
835 /**
836 * Override the default text for the *clear* icon button.
837 *
838 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
839 * @default 'Clear'
840 */
841 clearText: _propTypes.default.string,
842 /**
843 * Override the default text for the *close popup* icon button.
844 *
845 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
846 * @default 'Close'
847 */
848 closeText: _propTypes.default.string,
849 /**
850 * The props used for each slot inside.
851 * @deprecated Use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
852 */
853 componentsProps: _propTypes.default.shape({
854 clearIndicator: _propTypes.default.object,
855 paper: _propTypes.default.object,
856 popper: _propTypes.default.object,
857 popupIndicator: _propTypes.default.object
858 }),
859 /**
860 * The default value. Use when the component is not controlled.
861 * @default props.multiple ? [] : null
862 */
863 defaultValue: (0, _chainPropTypes.default)(_propTypes.default.any, props => {
864 if (props.multiple && props.defaultValue !== undefined && !Array.isArray(props.defaultValue)) {
865 return new Error(['MUI: The Autocomplete expects the `defaultValue` prop to be an array when `multiple={true}` or undefined.', `However, ${props.defaultValue} was provided.`].join('\n'));
866 }
867 return null;
868 }),
869 /**
870 * If `true`, the input can't be cleared.
871 * @default false
872 */
873 disableClearable: _propTypes.default.bool,
874 /**
875 * If `true`, the popup won't close when a value is selected.
876 * @default false
877 */
878 disableCloseOnSelect: _propTypes.default.bool,
879 /**
880 * If `true`, the component is disabled.
881 * @default false
882 */
883 disabled: _propTypes.default.bool,
884 /**
885 * If `true`, will allow focus on disabled items.
886 * @default false
887 */
888 disabledItemsFocusable: _propTypes.default.bool,
889 /**
890 * If `true`, the list box in the popup will not wrap focus.
891 * @default false
892 */
893 disableListWrap: _propTypes.default.bool,
894 /**
895 * If `true`, the `Popper` content will be under the DOM hierarchy of the parent component.
896 * @default false
897 */
898 disablePortal: _propTypes.default.bool,
899 /**
900 * A function that determines the filtered options to be rendered on search.
901 *
902 * @default createFilterOptions()
903 * @param {Value[]} options The options to render.
904 * @param {object} state The state of the component.
905 * @returns {Value[]}
906 */
907 filterOptions: _propTypes.default.func,
908 /**
909 * If `true`, hide the selected options from the list box.
910 * @default false
911 */
912 filterSelectedOptions: _propTypes.default.bool,
913 /**
914 * Force the visibility display of the popup icon.
915 * @default 'auto'
916 */
917 forcePopupIcon: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.bool]),
918 /**
919 * If `true`, the Autocomplete is free solo, meaning that the user input is not bound to provided options.
920 * @default false
921 */
922 freeSolo: _propTypes.default.bool,
923 /**
924 * If `true`, the input will take up the full width of its container.
925 * @default false
926 */
927 fullWidth: _propTypes.default.bool,
928 /**
929 * The label to display when the tags are truncated (`limitTags`).
930 *
931 * @param {number} more The number of truncated tags.
932 * @returns {ReactNode}
933 * @default (more) => `+${more}`
934 */
935 getLimitTagsText: _propTypes.default.func,
936 /**
937 * Used to determine the disabled state for a given option.
938 *
939 * @param {Value} option The option to test.
940 * @returns {boolean}
941 */
942 getOptionDisabled: _propTypes.default.func,
943 /**
944 * Used to determine the key for a given option.
945 * This can be useful when the labels of options are not unique (since labels are used as keys by default).
946 *
947 * @param {Value} option The option to get the key for.
948 * @returns {string | number}
949 */
950 getOptionKey: _propTypes.default.func,
951 /**
952 * Used to determine the string value for a given option.
953 * It's used to fill the input (and the list box options if `renderOption` is not provided).
954 *
955 * If used in free solo mode, it must accept both the type of the options and a string.
956 *
957 * @param {Value} option
958 * @returns {string}
959 * @default (option) => option.label ?? option
960 */
961 getOptionLabel: _propTypes.default.func,
962 /**
963 * If provided, the options will be grouped under the returned string.
964 * The groupBy value is also used as the text for group headings when `renderGroup` is not provided.
965 *
966 * @param {Value} options The options to group.
967 * @returns {string}
968 */
969 groupBy: _propTypes.default.func,
970 /**
971 * If `true`, the component handles the "Home" and "End" keys when the popup is open.
972 * It should move focus to the first option and last option, respectively.
973 * @default !props.freeSolo
974 */
975 handleHomeEndKeys: _propTypes.default.bool,
976 /**
977 * This prop is used to help implement the accessibility logic.
978 * If you don't provide an id it will fall back to a randomly generated one.
979 */
980 id: _propTypes.default.string,
981 /**
982 * If `true`, the highlight can move to the input.
983 * @default false
984 */
985 includeInputInList: _propTypes.default.bool,
986 /**
987 * The input value.
988 */
989 inputValue: _propTypes.default.string,
990 /**
991 * Used to determine if the option represents the given value.
992 * Uses strict equality by default.
993 * ⚠️ Both arguments need to be handled, an option can only match with one value.
994 *
995 * @param {Value} option The option to test.
996 * @param {Value} value The value to test against.
997 * @returns {boolean}
998 */
999 isOptionEqualToValue: _propTypes.default.func,
1000 /**
1001 * The maximum number of tags that will be visible when not focused.
1002 * Set `-1` to disable the limit.
1003 * @default -1
1004 */
1005 limitTags: _integerPropType.default,
1006 /**
1007 * The component used to render the listbox.
1008 * @default 'ul'
1009 */
1010 ListboxComponent: _propTypes.default.elementType,
1011 /**
1012 * Props applied to the Listbox element.
1013 */
1014 ListboxProps: _propTypes.default.object,
1015 /**
1016 * If `true`, the component is in a loading state.
1017 * This shows the `loadingText` in place of suggestions (only if there are no suggestions to show, for example `options` are empty).
1018 * @default false
1019 */
1020 loading: _propTypes.default.bool,
1021 /**
1022 * Text to display when in a loading state.
1023 *
1024 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
1025 * @default 'Loading…'
1026 */
1027 loadingText: _propTypes.default.node,
1028 /**
1029 * If `true`, `value` must be an array and the menu will support multiple selections.
1030 * @default false
1031 */
1032 multiple: _propTypes.default.bool,
1033 /**
1034 * Text to display when there are no options.
1035 *
1036 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
1037 * @default 'No options'
1038 */
1039 noOptionsText: _propTypes.default.node,
1040 /**
1041 * Callback fired when the value changes.
1042 *
1043 * @param {React.SyntheticEvent} event The event source of the callback.
1044 * @param {Value|Value[]} value The new value of the component.
1045 * @param {string} reason One of "createOption", "selectOption", "removeOption", "blur" or "clear".
1046 * @param {string} [details]
1047 */
1048 onChange: _propTypes.default.func,
1049 /**
1050 * Callback fired when the popup requests to be closed.
1051 * Use in controlled mode (see open).
1052 *
1053 * @param {React.SyntheticEvent} event The event source of the callback.
1054 * @param {string} reason Can be: `"toggleInput"`, `"escape"`, `"selectOption"`, `"removeOption"`, `"blur"`.
1055 */
1056 onClose: _propTypes.default.func,
1057 /**
1058 * Callback fired when the highlight option changes.
1059 *
1060 * @param {React.SyntheticEvent} event The event source of the callback.
1061 * @param {Value} option The highlighted option.
1062 * @param {string} reason Can be: `"keyboard"`, `"auto"`, `"mouse"`, `"touch"`.
1063 */
1064 onHighlightChange: _propTypes.default.func,
1065 /**
1066 * Callback fired when the input value changes.
1067 *
1068 * @param {React.SyntheticEvent} event The event source of the callback.
1069 * @param {string} value The new value of the text input.
1070 * @param {string} reason Can be: `"input"` (user input), `"reset"` (programmatic change), `"clear"`, `"blur"`, `"selectOption"`, `"removeOption"`
1071 */
1072 onInputChange: _propTypes.default.func,
1073 /**
1074 * @ignore
1075 */
1076 onKeyDown: _propTypes.default.func,
1077 /**
1078 * Callback fired when the popup requests to be opened.
1079 * Use in controlled mode (see open).
1080 *
1081 * @param {React.SyntheticEvent} event The event source of the callback.
1082 */
1083 onOpen: _propTypes.default.func,
1084 /**
1085 * If `true`, the component is shown.
1086 */
1087 open: _propTypes.default.bool,
1088 /**
1089 * If `true`, the popup will open on input focus.
1090 * @default false
1091 */
1092 openOnFocus: _propTypes.default.bool,
1093 /**
1094 * Override the default text for the *open popup* icon button.
1095 *
1096 * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
1097 * @default 'Open'
1098 */
1099 openText: _propTypes.default.string,
1100 /**
1101 * A list of options that will be shown in the Autocomplete.
1102 */
1103 options: _propTypes.default.array.isRequired,
1104 /**
1105 * The component used to render the body of the popup.
1106 * @default Paper
1107 */
1108 PaperComponent: _propTypes.default.elementType,
1109 /**
1110 * The component used to position the popup.
1111 * @default Popper
1112 */
1113 PopperComponent: _propTypes.default.elementType,
1114 /**
1115 * The icon to display in place of the default popup icon.
1116 * @default <ArrowDropDownIcon />
1117 */
1118 popupIcon: _propTypes.default.node,
1119 /**
1120 * If `true`, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
1121 * @default false
1122 */
1123 readOnly: _propTypes.default.bool,
1124 /**
1125 * Render the group.
1126 *
1127 * @param {AutocompleteRenderGroupParams} params The group to render.
1128 * @returns {ReactNode}
1129 */
1130 renderGroup: _propTypes.default.func,
1131 /**
1132 * Render the input.
1133 *
1134 * @param {object} params
1135 * @returns {ReactNode}
1136 */
1137 renderInput: _propTypes.default.func.isRequired,
1138 /**
1139 * Render the option, use `getOptionLabel` by default.
1140 *
1141 * @param {object} props The props to apply on the li element.
1142 * @param {Value} option The option to render.
1143 * @param {object} state The state of each option.
1144 * @param {object} ownerState The state of the Autocomplete component.
1145 * @returns {ReactNode}
1146 */
1147 renderOption: _propTypes.default.func,
1148 /**
1149 * Render the selected value.
1150 *
1151 * @param {Value[]} value The `value` provided to the component.
1152 * @param {function} getTagProps A tag props getter.
1153 * @param {object} ownerState The state of the Autocomplete component.
1154 * @returns {ReactNode}
1155 */
1156 renderTags: _propTypes.default.func,
1157 /**
1158 * If `true`, the input's text is selected on focus.
1159 * It helps the user clear the selected value.
1160 * @default !props.freeSolo
1161 */
1162 selectOnFocus: _propTypes.default.bool,
1163 /**
1164 * The size of the component.
1165 * @default 'medium'
1166 */
1167 size: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['small', 'medium']), _propTypes.default.string]),
1168 /**
1169 * The props used for each slot inside.
1170 * @default {}
1171 */
1172 slotProps: _propTypes.default /* @typescript-to-proptypes-ignore */.shape({
1173 chip: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
1174 clearIndicator: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
1175 listbox: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
1176 paper: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
1177 popper: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
1178 popupIndicator: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object])
1179 }),
1180 /**
1181 * The components used for each slot inside.
1182 * @default {}
1183 */
1184 slots: _propTypes.default.shape({
1185 listbox: _propTypes.default.elementType,
1186 paper: _propTypes.default.elementType,
1187 popper: _propTypes.default.elementType
1188 }),
1189 /**
1190 * The system prop that allows defining system overrides as well as additional CSS styles.
1191 */
1192 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
1193 /**
1194 * The value of the autocomplete.
1195 *
1196 * The value must have reference equality with the option in order to be selected.
1197 * You can customize the equality behavior with the `isOptionEqualToValue` prop.
1198 */
1199 value: (0, _chainPropTypes.default)(_propTypes.default.any, props => {
1200 if (props.multiple && props.value !== undefined && !Array.isArray(props.value)) {
1201 return new Error(['MUI: The Autocomplete expects the `value` prop to be an array when `multiple={true}` or undefined.', `However, ${props.value} was provided.`].join('\n'));
1202 }
1203 return null;
1204 })
1205} : void 0;
1206var _default = exports.default = Autocomplete;
\No newline at end of file