From bfcb0b66adb21c0f1f0942f9321a54dd83711196 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 22:26:22 +0200 Subject: [PATCH] [core] Fix a few more key spread issues (@oliviertassinari) (#42318) Co-authored-by: Olivier Tassinari --- .../components/autocomplete/CustomizedHook.js | 22 +++++++++++-------- .../autocomplete/CustomizedHook.tsx | 22 +++++++++++-------- .../material/components/autocomplete/Tags.js | 9 +++++--- .../material/components/autocomplete/Tags.tsx | 9 +++++--- docs/pages/base-ui/api/use-autocomplete.json | 4 ++-- .../src/useAutocomplete/useAutocomplete.d.ts | 2 +- .../src/Autocomplete/Autocomplete.js | 3 ++- 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/docs/data/material/components/autocomplete/CustomizedHook.js b/docs/data/material/components/autocomplete/CustomizedHook.js index 2d4b116616e83e..54dacedfde7591 100644 --- a/docs/data/material/components/autocomplete/CustomizedHook.js +++ b/docs/data/material/components/autocomplete/CustomizedHook.js @@ -181,20 +181,24 @@ export default function CustomizedHook() {
- {value.map((option, index) => ( - - ))} + {value.map((option, index) => { + const { key, ...tagProps } = getTagProps({ index }); + return ; + })}
{groupedOptions.length > 0 ? ( - {groupedOptions.map((option, index) => ( -
  • - {option.title} - -
  • - ))} + {groupedOptions.map((option, index) => { + const { key, ...optionProps } = getOptionProps({ option, index }); + return ( +
  • + {option.title} + +
  • + ); + })}
    ) : null} diff --git a/docs/data/material/components/autocomplete/CustomizedHook.tsx b/docs/data/material/components/autocomplete/CustomizedHook.tsx index 5fdd16e7cfae6a..66a216c698c4d7 100644 --- a/docs/data/material/components/autocomplete/CustomizedHook.tsx +++ b/docs/data/material/components/autocomplete/CustomizedHook.tsx @@ -179,20 +179,24 @@ export default function CustomizedHook() {
    - {value.map((option: FilmOptionType, index: number) => ( - - ))} + {value.map((option: FilmOptionType, index: number) => { + const { key, ...tagProps } = getTagProps({ index }); + return ; + })}
    {groupedOptions.length > 0 ? ( - {(groupedOptions as typeof top100Films).map((option, index) => ( -
  • - {option.title} - -
  • - ))} + {(groupedOptions as typeof top100Films).map((option, index) => { + const { key, ...optionProps } = getOptionProps({ option, index }); + return ( +
  • + {option.title} + +
  • + ); + })}
    ) : null} diff --git a/docs/data/material/components/autocomplete/Tags.js b/docs/data/material/components/autocomplete/Tags.js index 4e1de13f5d346e..05467cceca296b 100644 --- a/docs/data/material/components/autocomplete/Tags.js +++ b/docs/data/material/components/autocomplete/Tags.js @@ -44,9 +44,12 @@ export default function Tags() { defaultValue={[top100Films[13].title]} freeSolo renderTags={(value, getTagProps) => - value.map((option, index) => ( - - )) + value.map((option, index) => { + const { key, ...tagProps } = getTagProps({ index }); + return ( + + ); + }) } renderInput={(params) => ( - value.map((option: string, index: number) => ( - - )) + value.map((option: string, index: number) => { + const { key, ...tagProps } = getTagProps({ index }); + return ( + + ); + }) } renderInput={(params) => ( , - ) => React.HTMLAttributes; + ) => React.HTMLAttributes & { key: any }; /** * Id for the Autocomplete. */ diff --git a/packages/mui-material/src/Autocomplete/Autocomplete.js b/packages/mui-material/src/Autocomplete/Autocomplete.js index a81286fc3615ea..301c876212c78f 100644 --- a/packages/mui-material/src/Autocomplete/Autocomplete.js +++ b/packages/mui-material/src/Autocomplete/Autocomplete.js @@ -593,8 +593,9 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) { const renderGroup = renderGroupProp || defaultRenderGroup; const defaultRenderOption = (props2, option) => { // Need to clearly apply key because of https://github.com/vercel/next.js/issues/55642 + const { key, ...otherProps } = props2; return ( -
  • +
  • {getOptionLabel(option)}
  • );