From 70041ad16abc3969cb0993eec0ed1adaf756612e Mon Sep 17 00:00:00 2001 From: Diego Andai Date: Mon, 20 May 2024 07:17:24 -0400 Subject: [PATCH] [material-ui][TextField] Deprecate `*Props` props (#42062) --- .../components/autocomplete/Asynchronous.js | 18 +-- .../components/autocomplete/Asynchronous.tsx | 18 +-- .../components/autocomplete/CountrySelect.js | 8 +- .../components/autocomplete/CountrySelect.tsx | 8 +- .../components/autocomplete/FreeSolo.js | 8 +- .../components/autocomplete/FreeSolo.tsx | 8 +- .../components/popper/ScrollPlayground.js | 65 +++++---- .../text-fields/CustomizedInputsStyled.js | 7 +- .../text-fields/CustomizedInputsStyled.tsx | 4 +- .../text-fields/FormPropsTextFields.js | 44 +++--- .../text-fields/FormPropsTextFields.tsx | 44 +++--- .../components/text-fields/FormattedInputs.js | 6 +- .../text-fields/FormattedInputs.tsx | 6 +- .../components/text-fields/InputAdornments.js | 18 ++- .../text-fields/InputAdornments.tsx | 18 ++- .../components/text-fields/InputWithIcon.js | 14 +- .../components/text-fields/InputWithIcon.tsx | 14 +- .../text-fields/SelectTextFields.js | 18 ++- .../text-fields/SelectTextFields.tsx | 18 ++- .../landing-page/components/Footer.js | 8 +- .../landing-page/components/Footer.tsx | 8 +- .../templates/landing-page/components/Hero.js | 8 +- .../landing-page/components/Hero.tsx | 8 +- .../migrating-from-deprecated-apis.md | 29 ++++ docs/pages/material-ui/api/text-field.json | 77 +++++++++- .../onepirate/modules/components/TextField.js | 3 + .../onepirate/modules/form/RFTextField.js | 1 + .../api-docs/text-field/text-field.json | 11 +- packages/mui-codemod/CONTRIBUTING.md | 1 + packages/mui-codemod/README.md | 23 +++ .../src/deprecations/all/deprecations-all.js | 2 + .../deprecations/text-field-props/index.js | 1 + .../text-field-props/test-cases/actual.js | 24 ++++ .../text-field-props/test-cases/expected.js | 26 ++++ .../test-cases/theme.actual.js | 11 ++ .../test-cases/theme.expected.js | 13 ++ .../text-field-props/text-field-props.js | 48 +++++++ .../text-field-props/text-field-props.test.js | 16 +++ packages/mui-codemod/testUtils/index.js | 29 +++- .../src/FormHelperText/FormHelperText.js | 5 +- .../mui-material/src/InputBase/InputBase.js | 7 +- .../mui-material/src/InputLabel/InputLabel.js | 2 +- .../mui-material/src/Select/SelectInput.js | 2 +- .../mui-material/src/TextField/TextField.d.ts | 61 +++++++- .../mui-material/src/TextField/TextField.js | 131 ++++++++++++++---- .../src/TextField/TextField.test.js | 68 +++++++-- 46 files changed, 771 insertions(+), 196 deletions(-) create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/index.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/test-cases/actual.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/test-cases/expected.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/test-cases/theme.actual.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/test-cases/theme.expected.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/text-field-props.js create mode 100644 packages/mui-codemod/src/deprecations/text-field-props/text-field-props.test.js diff --git a/docs/data/material/components/autocomplete/Asynchronous.js b/docs/data/material/components/autocomplete/Asynchronous.js index 9244ba11f5b8ef..969f62e5cd28ae 100644 --- a/docs/data/material/components/autocomplete/Asynchronous.js +++ b/docs/data/material/components/autocomplete/Asynchronous.js @@ -60,14 +60,16 @@ export default function Asynchronous() { - {loading ? : null} - {params.InputProps.endAdornment} - - ), + slotProps={{ + input: { + ...params.InputProps, + endAdornment: ( + + {loading ? : null} + {params.InputProps.endAdornment} + + ), + }, }} /> )} diff --git a/docs/data/material/components/autocomplete/Asynchronous.tsx b/docs/data/material/components/autocomplete/Asynchronous.tsx index 382bcc2b1dcb97..82c009c528ba2d 100644 --- a/docs/data/material/components/autocomplete/Asynchronous.tsx +++ b/docs/data/material/components/autocomplete/Asynchronous.tsx @@ -65,14 +65,16 @@ export default function Asynchronous() { - {loading ? : null} - {params.InputProps.endAdornment} - - ), + slotProps={{ + input: { + ...params.InputProps, + endAdornment: ( + + {loading ? : null} + {params.InputProps.endAdornment} + + ), + }, }} /> )} diff --git a/docs/data/material/components/autocomplete/CountrySelect.js b/docs/data/material/components/autocomplete/CountrySelect.js index da2dfec88e27cd..d9b9dc9a348435 100644 --- a/docs/data/material/components/autocomplete/CountrySelect.js +++ b/docs/data/material/components/autocomplete/CountrySelect.js @@ -27,9 +27,11 @@ export default function CountrySelect() { )} diff --git a/docs/data/material/components/autocomplete/CountrySelect.tsx b/docs/data/material/components/autocomplete/CountrySelect.tsx index 4c26d29c2c04ce..897c3c197476ce 100644 --- a/docs/data/material/components/autocomplete/CountrySelect.tsx +++ b/docs/data/material/components/autocomplete/CountrySelect.tsx @@ -27,9 +27,11 @@ export default function CountrySelect() { )} diff --git a/docs/data/material/components/autocomplete/FreeSolo.js b/docs/data/material/components/autocomplete/FreeSolo.js index d2b6b33c81680a..981c001d25ad78 100644 --- a/docs/data/material/components/autocomplete/FreeSolo.js +++ b/docs/data/material/components/autocomplete/FreeSolo.js @@ -21,9 +21,11 @@ export default function FreeSolo() { )} diff --git a/docs/data/material/components/autocomplete/FreeSolo.tsx b/docs/data/material/components/autocomplete/FreeSolo.tsx index d2b6b33c81680a..981c001d25ad78 100644 --- a/docs/data/material/components/autocomplete/FreeSolo.tsx +++ b/docs/data/material/components/autocomplete/FreeSolo.tsx @@ -21,9 +21,11 @@ export default function FreeSolo() { )} diff --git a/docs/data/material/components/popper/ScrollPlayground.js b/docs/data/material/components/popper/ScrollPlayground.js index 24cbe701c2f13a..faeebbc1c5e053 100644 --- a/docs/data/material/components/popper/ScrollPlayground.js +++ b/docs/data/material/components/popper/ScrollPlayground.js @@ -275,20 +275,23 @@ export default function ScrollPlayground() { sx={{ width: 200 }} label="Placement" select - InputLabelProps={{ - id: 'scroll-playground-placement-label', - }} - SelectProps={{ - native: true, - inputProps: { - 'aria-labelledby': 'scroll-playground-placement-label', - }, - }} value={placement} onChange={(event) => { setPlacement(event.target.value); }} variant="standard" + slotProps={{ + select: { + native: true, + inputProps: { + 'aria-labelledby': 'scroll-playground-placement-label', + }, + }, + + inputLabel: { + id: 'scroll-playground-placement-label', + }, + }} > @@ -396,16 +399,6 @@ export default function ScrollPlayground() { size="small" label="Root Boundary" select - InputLabelProps={{ - id: 'scroll-playground-prevent-overflow-root-boundary', - }} - SelectProps={{ - native: true, - inputProps: { - 'aria-labelledby': - 'scroll-playground-prevent-overflow-root-boundary', - }, - }} value={preventOverflow.rootBoundary} onChange={(event) => { setPreventOverflow((old) => ({ @@ -414,6 +407,19 @@ export default function ScrollPlayground() { })); }} variant="standard" + slotProps={{ + select: { + native: true, + inputProps: { + 'aria-labelledby': + 'scroll-playground-prevent-overflow-root-boundary', + }, + }, + + inputLabel: { + id: 'scroll-playground-prevent-overflow-root-boundary', + }, + }} > @@ -458,15 +464,6 @@ export default function ScrollPlayground() { size="small" label="Root Boundary" select - InputLabelProps={{ - id: 'scroll-playground-flip-root-boundary', - }} - SelectProps={{ - native: true, - inputProps: { - 'aria-labelledby': 'scroll-playground-flip-root-boundary', - }, - }} value={flip.rootBoundary} onChange={(event) => { setFlip((old) => ({ @@ -475,6 +472,18 @@ export default function ScrollPlayground() { })); }} variant="standard" + slotProps={{ + select: { + native: true, + inputProps: { + 'aria-labelledby': 'scroll-playground-flip-root-boundary', + }, + }, + + inputLabel: { + id: 'scroll-playground-flip-root-boundary', + }, + }} > diff --git a/docs/data/material/components/text-fields/CustomizedInputsStyled.js b/docs/data/material/components/text-fields/CustomizedInputsStyled.js index 70306371e8e40e..2855127eb80f9a 100644 --- a/docs/data/material/components/text-fields/CustomizedInputsStyled.js +++ b/docs/data/material/components/text-fields/CustomizedInputsStyled.js @@ -65,7 +65,12 @@ const BootstrapInput = styled(InputBase)(({ theme }) => ({ })); const RedditTextField = styled((props) => ( - + ))(({ theme }) => ({ '& .MuiFilledInput-root': { overflow: 'hidden', diff --git a/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx b/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx index 825a6b7cde9f77..ef7ee416c73896 100644 --- a/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx +++ b/docs/data/material/components/text-fields/CustomizedInputsStyled.tsx @@ -67,7 +67,9 @@ const BootstrapInput = styled(InputBase)(({ theme }) => ({ const RedditTextField = styled((props: TextFieldProps) => ( } + slotProps={{ + input: { disableUnderline: true } as Partial, + }} {...props} /> ))(({ theme }) => ({ diff --git a/docs/data/material/components/text-fields/FormPropsTextFields.js b/docs/data/material/components/text-fields/FormPropsTextFields.js index 548213006a755e..33d7f6dff4b3b5 100644 --- a/docs/data/material/components/text-fields/FormPropsTextFields.js +++ b/docs/data/material/components/text-fields/FormPropsTextFields.js @@ -35,16 +35,20 @@ export default function FormPropsTextFields() { id="outlined-read-only-input" label="Read Only" defaultValue="Hello World" - InputProps={{ - readOnly: true, + slotProps={{ + input: { + readOnly: true, + }, }} /> @@ -81,19 +85,23 @@ export default function FormPropsTextFields() { id="filled-read-only-input" label="Read Only" defaultValue="Hello World" - InputProps={{ - readOnly: true, - }} variant="filled" + slotProps={{ + input: { + readOnly: true, + }, + }} /> @@ -81,19 +85,23 @@ export default function FormPropsTextFields() { id="filled-read-only-input" label="Read Only" defaultValue="Hello World" - InputProps={{ - readOnly: true, - }} variant="filled" + slotProps={{ + input: { + readOnly: true, + }, + }} /> diff --git a/docs/data/material/components/text-fields/FormattedInputs.tsx b/docs/data/material/components/text-fields/FormattedInputs.tsx index f14a821f121e7f..86bc31d4208c5f 100644 --- a/docs/data/material/components/text-fields/FormattedInputs.tsx +++ b/docs/data/material/components/text-fields/FormattedInputs.tsx @@ -85,8 +85,10 @@ export default function FormattedInputs() { onChange={handleChange} name="numberformat" id="formatted-numberformat-input" - InputProps={{ - inputComponent: NumericFormatCustom as any, + slotProps={{ + input: { + inputComponent: NumericFormatCustom as any, + }, }} variant="standard" /> diff --git a/docs/data/material/components/text-fields/InputAdornments.js b/docs/data/material/components/text-fields/InputAdornments.js index a6e64b12a43855..39a5c219e43d2e 100644 --- a/docs/data/material/components/text-fields/InputAdornments.js +++ b/docs/data/material/components/text-fields/InputAdornments.js @@ -28,8 +28,10 @@ export default function InputAdornments() { label="With normal TextField" id="outlined-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} /> @@ -77,8 +79,10 @@ export default function InputAdornments() { label="With normal TextField" id="filled-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} variant="filled" /> @@ -125,8 +129,10 @@ export default function InputAdornments() { label="With normal TextField" id="standard-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} variant="standard" /> diff --git a/docs/data/material/components/text-fields/InputAdornments.tsx b/docs/data/material/components/text-fields/InputAdornments.tsx index 0701e18cc5301e..a347354809a2fc 100644 --- a/docs/data/material/components/text-fields/InputAdornments.tsx +++ b/docs/data/material/components/text-fields/InputAdornments.tsx @@ -28,8 +28,10 @@ export default function InputAdornments() { label="With normal TextField" id="outlined-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} /> @@ -77,8 +79,10 @@ export default function InputAdornments() { label="With normal TextField" id="filled-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} variant="filled" /> @@ -125,8 +129,10 @@ export default function InputAdornments() { label="With normal TextField" id="standard-start-adornment" sx={{ m: 1, width: '25ch' }} - InputProps={{ - startAdornment: kg, + slotProps={{ + input: { + startAdornment: kg, + }, }} variant="standard" /> diff --git a/docs/data/material/components/text-fields/InputWithIcon.js b/docs/data/material/components/text-fields/InputWithIcon.js index 2967d1d9432b25..95293ef333bdf9 100644 --- a/docs/data/material/components/text-fields/InputWithIcon.js +++ b/docs/data/material/components/text-fields/InputWithIcon.js @@ -26,12 +26,14 @@ export default function InputWithIcon() { - - - ), + slotProps={{ + input: { + startAdornment: ( + + + + ), + }, }} variant="standard" /> diff --git a/docs/data/material/components/text-fields/InputWithIcon.tsx b/docs/data/material/components/text-fields/InputWithIcon.tsx index 2967d1d9432b25..95293ef333bdf9 100644 --- a/docs/data/material/components/text-fields/InputWithIcon.tsx +++ b/docs/data/material/components/text-fields/InputWithIcon.tsx @@ -26,12 +26,14 @@ export default function InputWithIcon() { - - - ), + slotProps={{ + input: { + startAdornment: ( + + + + ), + }, }} variant="standard" /> diff --git a/docs/data/material/components/text-fields/SelectTextFields.js b/docs/data/material/components/text-fields/SelectTextFields.js index 25a8e7ec321cff..ef7c5e00378222 100644 --- a/docs/data/material/components/text-fields/SelectTextFields.js +++ b/docs/data/material/components/text-fields/SelectTextFields.js @@ -51,8 +51,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" > @@ -83,8 +85,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" variant="filled" @@ -116,8 +120,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" variant="standard" diff --git a/docs/data/material/components/text-fields/SelectTextFields.tsx b/docs/data/material/components/text-fields/SelectTextFields.tsx index 25a8e7ec321cff..ef7c5e00378222 100644 --- a/docs/data/material/components/text-fields/SelectTextFields.tsx +++ b/docs/data/material/components/text-fields/SelectTextFields.tsx @@ -51,8 +51,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" > @@ -83,8 +85,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" variant="filled" @@ -116,8 +120,10 @@ export default function SelectTextFields() { select label="Native select" defaultValue="EUR" - SelectProps={{ - native: true, + slotProps={{ + select: { + native: true, + }, }} helperText="Please select your currency" variant="standard" diff --git a/docs/data/material/getting-started/templates/landing-page/components/Footer.js b/docs/data/material/getting-started/templates/landing-page/components/Footer.js index 43aa5115caa990..984c992cd8c98e 100644 --- a/docs/data/material/getting-started/templates/landing-page/components/Footer.js +++ b/docs/data/material/getting-started/templates/landing-page/components/Footer.js @@ -75,9 +75,11 @@ export default function Footer() { fullWidth aria-label="Enter your email address" placeholder="Your email address" - inputProps={{ - autoComplete: 'off', - 'aria-label': 'Enter your email address', + slotProps={{ + htmlInput: { + autoComplete: 'off', + 'aria-label': 'Enter your email address', + }, }} />