Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions docs/pages/material-ui/api/autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"slots": {
"type": {
"name": "shape",
"description": "{ listbox?: elementType, paper?: elementType, popper?: elementType }"
"description": "{ clearIndicator?: elementType, listbox?: elementType, paper?: elementType, popper?: elementType, popupIndicator?: elementType }"
},
"default": "{}"
},
Expand All @@ -231,6 +231,18 @@
"import { Autocomplete } from '@mui/material';"
],
"slots": [
{
"name": "clearIndicator",
"description": "The component used to render the clear indicator element.",
"default": "IconButton",
"class": "MuiAutocomplete-clearIndicator"
},
{
"name": "popupIndicator",
"description": "The component used to render the popup indicator element.",
"default": "IconButton",
"class": "MuiAutocomplete-popupIndicator"
},
{
"name": "listbox",
"description": "The component used to render the listbox.",
Expand All @@ -251,12 +263,6 @@
}
],
"classes": [
{
"key": "clearIndicator",
"className": "MuiAutocomplete-clearIndicator",
"description": "Styles applied to the clear indicator.",
"isGlobal": false
},
{
"key": "endAdornment",
"className": "MuiAutocomplete-endAdornment",
Expand Down Expand Up @@ -353,12 +359,6 @@
"description": "Styles applied to the popper element if `disablePortal={true}`.",
"isGlobal": false
},
{
"key": "popupIndicator",
"className": "MuiAutocomplete-popupIndicator",
"description": "Styles applied to the popup indicator.",
"isGlobal": false
},
{
"key": "popupIndicatorOpen",
"className": "MuiAutocomplete-popupIndicatorOpen",
Expand Down
12 changes: 3 additions & 9 deletions docs/translations/api-docs/autocomplete/autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@
}
},
"classDescriptions": {
"clearIndicator": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the clear indicator"
},
"endAdornment": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the endAdornment element"
Expand Down Expand Up @@ -318,10 +314,6 @@
"nodeName": "the popper element",
"conditions": "<code>disablePortal={true}</code>"
},
"popupIndicator": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the popup indicator"
},
"popupIndicatorOpen": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the popup indicator",
Expand All @@ -345,8 +337,10 @@
}
},
"slotDescriptions": {
"clearIndicator": "The component used to render the clear indicator element.",
"listbox": "The component used to render the listbox.",
"paper": "The component used to render the body of the popup.",
"popper": "The component used to position the popup."
"popper": "The component used to position the popup.",
"popupIndicator": "The component used to render the popup indicator element."
}
}
10 changes: 10 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ export interface AutocompleteRenderInputParams {
export interface AutocompletePropsSizeOverrides {}

export interface AutocompleteSlots {
/**
* The component used to render the clear indicator element.
* @default IconButton
*/
clearIndicator: React.JSXElementConstructor<IconButtonProps>;
/**
* The component used to render the popup indicator element.
* @default IconButton
*/
popupIndicator: React.JSXElementConstructor<IconButtonProps>;
/**
* The component used to render the listbox.
* @default 'ul'
Expand Down
56 changes: 31 additions & 25 deletions packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,33 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
},
});

const [ClearIndicatorSlot, clearIndicatorProps] = useSlot('clearIndicator', {
elementType: AutocompleteClearIndicator,
externalForwardedProps,
ownerState,
className: classes.clearIndicator,
shouldForwardComponentProp: true,
additionalProps: {
...getClearProps(),
'aria-label': clearText,
title: clearText,
},
});

const [PopupIndicatorSlot, popupIndicatorProps] = useSlot('popupIndicator', {
elementType: AutocompletePopupIndicator,
externalForwardedProps,
ownerState,
className: classes.popupIndicator,
shouldForwardComponentProp: true,
additionalProps: {
...getPopupIndicatorProps(),
disabled,
'aria-label': popupOpen ? closeText : openText,
title: popupOpen ? closeText : openText,
},
});

let startAdornment;

const getCustomizedItemProps = (params) => ({
Expand Down Expand Up @@ -663,9 +690,6 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
);
};

const clearIndicatorSlotProps = externalForwardedProps.slotProps.clearIndicator;
const popupIndicatorSlotProps = externalForwardedProps.slotProps.popupIndicator;

return (
<React.Fragment>
<AutocompleteRoot
Expand Down Expand Up @@ -693,30 +717,10 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
endAdornment: (
<AutocompleteEndAdornment className={classes.endAdornment} ownerState={ownerState}>
{hasClearIcon ? (
<AutocompleteClearIndicator
{...getClearProps()}
aria-label={clearText}
title={clearText}
ownerState={ownerState}
{...clearIndicatorSlotProps}
className={clsx(classes.clearIndicator, clearIndicatorSlotProps?.className)}
>
{clearIcon}
</AutocompleteClearIndicator>
<ClearIndicatorSlot {...clearIndicatorProps}>{clearIcon}</ClearIndicatorSlot>
) : null}

{hasPopupIcon ? (
<AutocompletePopupIndicator
{...getPopupIndicatorProps()}
disabled={disabled}
aria-label={popupOpen ? closeText : openText}
title={popupOpen ? closeText : openText}
ownerState={ownerState}
{...popupIndicatorSlotProps}
className={clsx(classes.popupIndicator, popupIndicatorSlotProps?.className)}
>
{popupIcon}
</AutocompletePopupIndicator>
<PopupIndicatorSlot {...popupIndicatorProps}>{popupIcon}</PopupIndicatorSlot>
) : null}
</AutocompleteEndAdornment>
),
Expand Down Expand Up @@ -1223,9 +1227,11 @@ Autocomplete.propTypes /* remove-proptypes */ = {
* @default {}
*/
slots: PropTypes.shape({
clearIndicator: PropTypes.elementType,
listbox: PropTypes.elementType,
paper: PropTypes.elementType,
popper: PropTypes.elementType,
popupIndicator: PropTypes.elementType,
}),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
Expand Down
7 changes: 6 additions & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ describe('<Autocomplete />', () => {
clearIndicator: { expectedClassName: classes.clearIndicator },
popupIndicator: { expectedClassName: classes.popupIndicator },
},
only: ['slotPropsProp'],
only: [
'slotsProp',
'slotPropsProp',
'slotPropsCallback',
'slotPropsCallbackWithPropsAsOwnerState',
],
}),
);

Expand Down
Loading