Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Autocomplete] deprecate *Component and *Props for v6 #41875

Merged
merged 24 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d22419d
deprecate *Component and *Props with codemod
lhilgert9 Apr 12, 2024
3014b3a
Update packages/mui-material/src/Autocomplete/Autocomplete.d.ts
lhilgert9 Apr 25, 2024
35491c1
Merge branch 'next' into deprecate-autocomple-props
lhilgert9 Apr 25, 2024
9f03cea
use same props as in component props
lhilgert9 Apr 25, 2024
ee9d557
Fix paper slots and slotProps types
lhilgert9 Apr 25, 2024
7b9e3b6
fix proptypes
lhilgert9 Apr 26, 2024
83d8ab3
Merge remote-tracking branch 'upstream' into deprecate-autocomplete-p…
lhilgert9 Apr 26, 2024
8bc86ad
run docs:api
lhilgert9 Apr 26, 2024
834d1e1
fix slots props to be optional
lhilgert9 Apr 26, 2024
44f5c0b
change demos to use slots and slotProps
lhilgert9 Apr 30, 2024
32ce9b4
Merge remote-tracking branch 'upstream' into deprecate-autocomple-props
lhilgert9 Apr 30, 2024
dfdbf4d
pnpm docs:typescript:formatted
lhilgert9 Apr 30, 2024
fe2401d
fix proptypes
lhilgert9 May 1, 2024
7cea30a
fix slotProps types to accept functions
lhilgert9 May 2, 2024
c5ffabe
add explanation for deprecated api's
lhilgert9 May 4, 2024
e2dcb00
Merge remote-tracking branch 'upstream/next' into deprecate-autocompl…
lhilgert9 May 4, 2024
be30a71
fix missing ","
lhilgert9 May 4, 2024
1a8ebb9
migrate Autocomplete tests to not use deprecated apis
lhilgert9 May 4, 2024
8ffaab6
Revert "migrate Autocomplete tests to not use deprecated apis"
DiegoAndai May 7, 2024
0f8665c
Update migrating guide link messages
DiegoAndai May 7, 2024
e7a5e56
Update codemod install version
DiegoAndai May 7, 2024
4960559
Update tests
DiegoAndai May 7, 2024
96d8b77
pnpm docs:api
lhilgert9 May 7, 2024
d859029
trigger ci
DiegoAndai May 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ 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@latest deprecations/autocomplete-props <path>
```

lhilgert9 marked this conversation as resolved.
Show resolved Hide resolved
## 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
80 changes: 56 additions & 24 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. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"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. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"ListboxProps": {
"type": { "name": "object" },
"deprecated": true,
"deprecationInfo": "Use <code>slotProps.listbox</code> instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"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. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
},
"PopperComponent": {
"type": { "name": "elementType" },
"default": "Popper",
"deprecated": true,
"deprecationInfo": "Use <code>slots.listbox</code> instead. This prop will be removed in v7. <a href=\"/material-ui/migration/migrating-from-deprecated-apis/\">How to migrate</a>."
lhilgert9 marked this conversation as resolved.
Show resolved Hide resolved
},
"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;{ avatar?: element, children?: any, classes?: any<br>&#124;&nbsp;object, className?: any<br>&#124;&nbsp;string, clickable?: any<br>&#124;&nbsp;bool, color?: 'default'<br>&#124;&nbsp;'error'<br>&#124;&nbsp;'info'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;'success'<br>&#124;&nbsp;'warning'<br>&#124;&nbsp;any, component?: elementType, deleteIcon?: element, disabled?: any<br>&#124;&nbsp;bool, icon?: element, label?: any<br>&#124;&nbsp;node, onDelete?: any<br>&#124;&nbsp;func, size?: 'medium'<br>&#124;&nbsp;'small'<br>&#124;&nbsp;any, skipFocusWhenDisabled?: any<br>&#124;&nbsp;bool, style?: any<br>&#124;&nbsp;object, sx?: any, tabIndex?: any<br>&#124;&nbsp;number, variant?: 'filled'<br>&#124;&nbsp;'outlined'<br>&#124;&nbsp;any }<br>&#124;&nbsp;{ component?: elementType, key?: any, sx?: Array&lt;func<br>&#124;&nbsp;object<br>&#124;&nbsp;bool&gt;<br>&#124;&nbsp;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
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 transformAvatarProps from '../avatar-props';
import transformDividerProps from '../divider-props';
import transformAccordionClasses from '../accordion-summary-classes';
Expand All @@ -18,6 +19,7 @@ import transformStepConnectorClasses from '../step-connector-classes';
*/
export default function deprecationsAll(file, api, options) {
file.source = transformAccordionProps(file, api, options);
file.source = transformAutocompleteProps(file, api, options);
file.source = transformAvatarProps(file, api, options);
file.source = transformDividerProps(file, api, options);
file.source = transformAccordionClasses(file, api, options);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import movePropIntoSlots from '../utils/movePropIntoSlots';
import movePropIntoSlotProps from '../utils/movePropIntoSlotProps';

/**
* @param {import('jscodeshift').FileInfo} file
* @param {import('jscodeshift').API} api
*/
export default function transformer(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
const printOptions = options.printOptions;

movePropIntoSlots(j, {
root,
componentName: 'Autocomplete',
propName: 'PaperComponent',
slotName: 'paper',
});

movePropIntoSlots(j, {
root,
componentName: 'Autocomplete',
propName: 'PopperComponent',
slotName: 'popper',
});

movePropIntoSlots(j, {
root,
componentName: 'Autocomplete',
propName: 'ListboxComponent',
slotName: 'listbox',
});

movePropIntoSlotProps(j, {
root,
componentName: 'Autocomplete',
propName: 'ListboxProps',
slotName: 'listbox',
});

movePropIntoSlotProps(j, {
root,
componentName: 'Autocomplete',
propName: 'ChipProps',
slotName: 'chip',
});

return root.toSource(printOptions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import path from 'path';
import { expect } from 'chai';
import { jscodeshift } from '../../../testUtils';
import transform from './autocomplete-props';
import readFile from '../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('autocomplete-props', () => {
it('transforms props as needed', () => {
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {});

const expected = read('./test-cases/expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent', () => {
const actual = transform({ source: read('./test-cases/expected.js') }, { jscodeshift }, {});

const expected = read('./test-cases/expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});

describe('[theme] autocomplete-props', () => {
it('transforms props as needed', () => {
const actual = transform(
{ source: read('./test-cases/theme.actual.js') },
{ jscodeshift },
{},
);

const expected = read('./test-cases/theme.expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent', () => {
const actual = transform(
{ source: read('./test-cases/theme.expected.js') },
{ jscodeshift },
{},
);

const expected = read('./test-cases/theme.expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './autocomplete-props';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Autocomplete from '@mui/material/Autocomplete';
import {Autocomplete as MyAutocomplete} from '@mui/material';

<Autocomplete
ChipProps={{ height: 10 }}
PaperComponent={CustomPaper}
PopperComponent={CustomPopper}
ListboxComponent={CustomListbox}
ListboxProps={{ height: 12 }}
/>;

<Autocomplete
ChipProps={{ height: 10 }}
PaperComponent={CustomPaper}
PopperComponent={CustomPopper}
ListboxComponent={CustomListbox}
ListboxProps={{ height: 12 }}
slotProps={{
popupIndicator: { width: 20 }
}}
/>;

<MyAutocomplete
ChipProps={{ height: 10 }}
PaperComponent={CustomPaper}
PopperComponent={CustomPopper}
ListboxComponent={CustomListbox}
ListboxProps={{ height: 12 }}
/>;

<CustomAutocomplete
ChipProps={{ height: 10 }}
PaperComponent={CustomPaper}
PopperComponent={CustomPopper}
ListboxComponent={CustomListbox}
ListboxProps={{ height: 12 }}
/>
Loading
Loading