Skip to content

Commit

Permalink
[material-ui][Autocomplete] deprecate *Component and *Props for v6 (
Browse files Browse the repository at this point in the history
  • Loading branch information
lhilgert9 committed May 8, 2024
1 parent 2f61ff7 commit d8a5f53
Show file tree
Hide file tree
Showing 20 changed files with 608 additions and 110 deletions.
4 changes: 3 additions & 1 deletion docs/data/material/components/autocomplete/GitHubLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export default function GitHubLabel() {
setPendingValue(newValue);
}}
disableCloseOnSelect
PopperComponent={PopperComponent}
renderTags={() => null}
noOptionsText="No labels"
renderOption={(props, option, { selected }) => (
Expand Down Expand Up @@ -255,6 +254,9 @@ export default function GitHubLabel() {
placeholder="Filter labels"
/>
)}
slots={{
popper: PopperComponent,
}}
/>
</div>
</ClickAwayListener>
Expand Down
4 changes: 3 additions & 1 deletion docs/data/material/components/autocomplete/GitHubLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ export default function GitHubLabel() {
setPendingValue(newValue);
}}
disableCloseOnSelect
PopperComponent={PopperComponent}
renderTags={() => null}
noOptionsText="No labels"
renderOption={(props, option, { selected }) => (
Expand Down Expand Up @@ -261,6 +260,9 @@ export default function GitHubLabel() {
placeholder="Filter labels"
/>
)}
slots={{
popper: PopperComponent,
}}
/>
</div>
</ClickAwayListener>
Expand Down
6 changes: 4 additions & 2 deletions docs/data/material/components/autocomplete/Virtualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ export default function Virtualize() {
<Autocomplete
sx={{ width: 300 }}
disableListWrap
PopperComponent={StyledPopper}
ListboxComponent={ListboxComponent}
options={OPTIONS}
groupBy={(option) => option[0].toUpperCase()}
renderInput={(params) => <TextField {...params} label="10,000 options" />}
renderOption={(props, option, state) => [props, option, state.index]}
renderGroup={(params) => params}
slots={{
popper: StyledPopper,
listbox: ListboxComponent,
}}
/>
);
}
6 changes: 4 additions & 2 deletions docs/data/material/components/autocomplete/Virtualize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ export default function Virtualize() {
<Autocomplete
sx={{ width: 300 }}
disableListWrap
PopperComponent={StyledPopper}
ListboxComponent={ListboxComponent}
options={OPTIONS}
groupBy={(option) => option[0].toUpperCase()}
renderInput={(params) => <TextField {...params} label="10,000 options" />}
renderOption={(props, option, state) =>
[props, option, state.index] as React.ReactNode
}
renderGroup={(params) => params as any}
slots={{
popper: StyledPopper,
listbox: ListboxComponent,
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Autocomplete
sx={{ width: 300 }}
disableListWrap
PopperComponent={StyledPopper}
ListboxComponent={ListboxComponent}
options={OPTIONS}
groupBy={(option) => option[0].toUpperCase()}
renderInput={(params) => <TextField {...params} label="10,000 options" />}
renderOption={(props, option, state) =>
[props, option, state.index] as React.ReactNode
}
renderGroup={(params) => params as any}
slots={{
popper: StyledPopper,
listbox: ListboxComponent,
}}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,46 @@ Here's how to migrate:
},
```

## Autocomplete

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#autocomplete-props) below to migrate the code as described in the following sections:

```bash
npx @mui/codemod@next deprecations/autocomplete-props <path>
```

### \*Component props

All of the Autocomplete's slot (`*Component`) props were deprecated in favor of equivalent `slots` entries:

```diff
<Autocomplete
- ListboxComponent={CustomListboxComponent}
- PaperComponent={CustomPaperComponent}
- PopperComponent={CustomPopperComponent}
+ slots={{
+ listbox: CustomListboxComponent,
+ paper: CustomPaperComponent,
+ popper: CustomPopperComponent,
+ }}
/>
```

### \*Props props

All of the Autocomplete's slot props (`*Props`) props were deprecated in favor of equivalent `slotProps` entries:

```diff
<Autocomplete
- ChipProps={CustomChipProps}
- ListboxProps={CustomListboxProps}
+ slotProps={{
+ chip: CustomChipProps,
+ listbox: CustomListboxProps,
+ }}
/>
```

## Avatar

Use the [codemod](https://github.com/mui/material-ui/tree/HEAD/packages/mui-codemod#avatar-props) below to migrate the code as described in the following sections:
Expand Down
81 changes: 56 additions & 25 deletions docs/pages/material-ui/api/autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
},
"default": "false"
},
"ChipProps": { "type": { "name": "object" } },
"ChipProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.chip</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"clearIcon": { "type": { "name": "node" }, "default": "<ClearIcon fontSize=\"small\" />" },
"clearOnBlur": { "type": { "name": "bool" }, "default": "!props.freeSolo" },
Expand Down Expand Up @@ -92,8 +96,17 @@
}
},
"limitTags": { "type": { "name": "custom", "description": "integer" }, "default": "-1" },
"ListboxComponent": { "type": { "name": "elementType" }, "default": "'ul'" },
"ListboxProps": { "type": { "name": "object" } },
"ListboxComponent": {
"type": { "name": "elementType" },
"default": "'ul'",
"deprecated": true,
"deprecationInfo": "Use <code>slots.listbox</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"ListboxProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.listbox</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"loading": { "type": { "name": "bool" }, "default": "false" },
"loadingText": { "type": { "name": "node" }, "default": "'Loading…'" },
"multiple": { "type": { "name": "bool" }, "default": "false" },
Expand Down Expand Up @@ -136,8 +149,18 @@
"open": { "type": { "name": "bool" } },
"openOnFocus": { "type": { "name": "bool" }, "default": "false" },
"openText": { "type": { "name": "string" }, "default": "'Open'" },
"PaperComponent": { "type": { "name": "elementType" }, "default": "Paper" },
"PopperComponent": { "type": { "name": "elementType" }, "default": "Popper" },
"PaperComponent": {
"type": { "name": "elementType" },
"default": "Paper",
"deprecated": true,
"deprecationInfo": "Use <code>slots.paper</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"PopperComponent": {
"type": { "name": "elementType" },
"default": "Popper",
"deprecated": true,
"deprecationInfo": "Use <code>slots.popper</code> instead. This prop will be removed in v7. See <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">Migrating from deprecated APIs</a> for more details."
},
"popupIcon": { "type": { "name": "node" }, "default": "<ArrowDropDownIcon />" },
"readOnly": { "type": { "name": "bool" }, "default": "false" },
"renderGroup": {
Expand Down Expand Up @@ -172,7 +195,14 @@
"slotProps": {
"type": {
"name": "shape",
"description": "{ clearIndicator?: object, paper?: object, popper?: object, popupIndicator?: object }"
"description": "{ chip?: func<br>&#124;&nbsp;object, clearIndicator?: func<br>&#124;&nbsp;object, listbox?: func<br>&#124;&nbsp;object, paper?: func<br>&#124;&nbsp;object, popper?: func<br>&#124;&nbsp;object, popupIndicator?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": {
"name": "shape",
"description": "{ listbox?: elementType, paper?: elementType, popper?: elementType }"
},
"default": "{}"
},
Expand All @@ -190,6 +220,26 @@
"import Autocomplete from '@mui/material/Autocomplete';",
"import { Autocomplete } from '@mui/material';"
],
"slots": [
{
"name": "listbox",
"description": "The component used to render the listbox.",
"default": "'ul'",
"class": "MuiAutocomplete-listbox"
},
{
"name": "paper",
"description": "The component used to render the body of the popup.",
"default": "Paper",
"class": "MuiAutocomplete-paper"
},
{
"name": "popper",
"description": "The component used to position the popup.",
"default": "Popper",
"class": "MuiAutocomplete-popper"
}
],
"classes": [
{
"key": "clearIndicator",
Expand Down Expand Up @@ -269,12 +319,6 @@
"description": "Styles applied to the Input element.",
"isGlobal": false
},
{
"key": "listbox",
"className": "MuiAutocomplete-listbox",
"description": "Styles applied to the listbox component.",
"isGlobal": false
},
{
"key": "loading",
"className": "MuiAutocomplete-loading",
Expand All @@ -293,18 +337,6 @@
"description": "Styles applied to the option elements.",
"isGlobal": false
},
{
"key": "paper",
"className": "MuiAutocomplete-paper",
"description": "Styles applied to the Paper component.",
"isGlobal": false
},
{
"key": "popper",
"className": "MuiAutocomplete-popper",
"description": "Styles applied to the popper element.",
"isGlobal": false
},
{
"key": "popperDisablePortal",
"className": "MuiAutocomplete-popperDisablePortal",
Expand Down Expand Up @@ -351,7 +383,6 @@
"spread": true,
"themeDefaultProps": true,
"muiName": "MuiAutocomplete",
"forwardsRefTo": "HTMLDivElement",
"filename": "/packages/mui-material/src/Autocomplete/Autocomplete.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/material-ui/react-autocomplete/\">Autocomplete</a></li></ul>",
Expand Down
18 changes: 6 additions & 12 deletions docs/translations/api-docs/autocomplete/autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
},
"size": { "description": "The size of the component." },
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"sx": {
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
},
Expand Down Expand Up @@ -245,10 +246,6 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the Input element"
},
"listbox": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the listbox component"
},
"loading": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the loading wrapper"
Expand All @@ -261,14 +258,6 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the option elements"
},
"paper": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the Paper component"
},
"popper": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the popper element"
},
"popperDisablePortal": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the popper element",
Expand Down Expand Up @@ -299,5 +288,10 @@
"nodeName": "the tag elements",
"conditions": "for example the chips if <code>size=\"small\"</code>"
}
},
"slotDescriptions": {
"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."
}
}
46 changes: 46 additions & 0 deletions packages/mui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,52 @@ npx @mui/codemod@next deprecations/alert-classes <path>
npx @mui/codemod@next deprecations/alert-props <path>
```

#### `autocomplete-props`

```diff
<Autocomplete
- ChipProps={{ height: 10 }}
- PaperComponent={CustomPaper}
- PopperComponent={CustomPopper}
- ListboxComponent={CustomListbox}
- ListboxProps={{ height: 12 }}
+ slots={{
+ paper: CustomPaper,
+ popper: CustomPopper,
+ listbox: CustomListbox,
+ }}
+ slotProps={{
+ chip: { height: 10 },
+ listbox: { height: 12 },
+ }}
/>
```

```diff
MuiAutocomplete: {
defaultProps: {
- ChipProps: { height: 10 },
- PaperComponent: CustomPaper,
- PopperComponent: CustomPopper,
- ListboxComponent: CustomListbox,
- ListboxProps: { height: 12 },
+ slots: {
+ paper: CustomPaper,
+ popper: CustomPopper,
+ listbox: CustomListbox,
+ },
+ slotProps: {
+ chip: { height: 10 },
+ listbox: { height: 12 },
+ },
},
},
```

```bash
npx @mui/codemod@next deprecations/autocomplete-props <path>
```

#### `avatar-props`

```diff
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-codemod/src/deprecations/all/deprecations-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import transformAccordionProps from '../accordion-props';
import transformAutocompleteProps from '../autocomplete-props';
import transformFormControlLabelProps from '../form-control-label-props';
import transformAvatarProps from '../avatar-props';
import transformDividerProps from '../divider-props';
Expand All @@ -21,6 +22,7 @@ import transformSpeedDialProps from '../speed-dial-props';
*/
export default function deprecationsAll(file, api, options) {
file.source = transformAccordionProps(file, api, options);
file.source = transformAutocompleteProps(file, api, options);
file.source = transformFormControlLabelProps(file, api, options);
file.source = transformAvatarProps(file, api, options);
file.source = transformDividerProps(file, api, options);
Expand Down
Loading

0 comments on commit d8a5f53

Please sign in to comment.