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
22 changes: 13 additions & 9 deletions docs/data/material/components/autocomplete/CustomizedHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,24 @@ export default function CustomizedHook() {
<div {...getRootProps()}>
<Label {...getInputLabelProps()}>Customized hook</Label>
<InputWrapper ref={setAnchorEl} className={focused ? 'focused' : ''}>
{value.map((option, index) => (
<StyledTag label={option.title} {...getTagProps({ index })} />
))}
{value.map((option, index) => {
const { key, ...tagProps } = getTagProps({ index });
return <StyledTag key={key} {...tagProps} label={option.title} />;
})}
<input {...getInputProps()} />
</InputWrapper>
</div>
{groupedOptions.length > 0 ? (
<Listbox {...getListboxProps()}>
{groupedOptions.map((option, index) => (
<li {...getOptionProps({ option, index })}>
<span>{option.title}</span>
<CheckIcon fontSize="small" />
</li>
))}
{groupedOptions.map((option, index) => {
const { key, ...optionProps } = getOptionProps({ option, index });
return (
<li key={key} {...optionProps}>
<span>{option.title}</span>
<CheckIcon fontSize="small" />
</li>
);
})}
</Listbox>
) : null}
</Root>
Expand Down
22 changes: 13 additions & 9 deletions docs/data/material/components/autocomplete/CustomizedHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,24 @@ export default function CustomizedHook() {
<div {...getRootProps()}>
<Label {...getInputLabelProps()}>Customized hook</Label>
<InputWrapper ref={setAnchorEl} className={focused ? 'focused' : ''}>
{value.map((option: FilmOptionType, index: number) => (
<StyledTag label={option.title} {...getTagProps({ index })} />
))}
{value.map((option: FilmOptionType, index: number) => {
const { key, ...tagProps } = getTagProps({ index });
return <StyledTag key={key} {...tagProps} label={option.title} />;
})}
<input {...getInputProps()} />
</InputWrapper>
</div>
{groupedOptions.length > 0 ? (
<Listbox {...getListboxProps()}>
{(groupedOptions as typeof top100Films).map((option, index) => (
<li {...getOptionProps({ option, index })}>
<span>{option.title}</span>
<CheckIcon fontSize="small" />
</li>
))}
{(groupedOptions as typeof top100Films).map((option, index) => {
const { key, ...optionProps } = getOptionProps({ option, index });
return (
<li key={key} {...optionProps}>
<span>{option.title}</span>
<CheckIcon fontSize="small" />
</li>
);
})}
</Listbox>
) : null}
</Root>
Expand Down
9 changes: 6 additions & 3 deletions docs/data/material/components/autocomplete/Tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export default function Tags() {
defaultValue={[top100Films[13].title]}
freeSolo
renderTags={(value, getTagProps) =>
value.map((option, index) => (
<Chip variant="outlined" label={option} {...getTagProps({ index })} />
))
value.map((option, index) => {
const { key, ...tagProps } = getTagProps({ index });
return (
<Chip variant="outlined" label={option} key={key} {...tagProps} />
);
})
}
renderInput={(params) => (
<TextField
Expand Down
9 changes: 6 additions & 3 deletions docs/data/material/components/autocomplete/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export default function Tags() {
defaultValue={[top100Films[13].title]}
freeSolo
renderTags={(value: readonly string[], getTagProps) =>
value.map((option: string, index: number) => (
<Chip variant="outlined" label={option} {...getTagProps({ index })} />
))
value.map((option: string, index: number) => {
const { key, ...tagProps } = getTagProps({ index });
return (
<Chip variant="outlined" label={option} key={key} {...tagProps} />
);
})
}
renderInput={(params) => (
<TextField
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/base-ui/api/use-autocomplete.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
},
"getOptionProps": {
"type": {
"name": "(renderedOption: UseAutocompleteRenderedOption&lt;Value&gt;) =&gt; React.HTMLAttributes&lt;HTMLLIElement&gt;",
"description": "(renderedOption: UseAutocompleteRenderedOption&lt;Value&gt;) =&gt; React.HTMLAttributes&lt;HTMLLIElement&gt;"
"name": "(renderedOption: UseAutocompleteRenderedOption&lt;Value&gt;) =&gt; React.HTMLAttributes&lt;HTMLLIElement&gt; &amp; { key: any }",
"description": "(renderedOption: UseAutocompleteRenderedOption&lt;Value&gt;) =&gt; React.HTMLAttributes&lt;HTMLLIElement&gt; &amp; { key: any }"
},
"required": true
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/useAutocomplete/useAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export interface UseAutocompleteReturnValue<
*/
getOptionProps: (
renderedOption: UseAutocompleteRenderedOption<Value>,
) => React.HTMLAttributes<HTMLLIElement>;
) => React.HTMLAttributes<HTMLLIElement> & { key: any };
/**
* Id for the Autocomplete.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<li {...props2} key={props2.key}>
<li key={key} {...otherProps}>
{getOptionLabel(option)}
</li>
);
Expand Down