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