Skip to content

Commit

Permalink
[material-ui][Autocomplete] Fix more React 18.3 key spread warnings i…
Browse files Browse the repository at this point in the history
…n demos (#42639)

Signed-off-by: wbt <[email protected]>
Co-authored-by: Aarón García Hervás <[email protected]>
  • Loading branch information
wbt and aarongarciah authored Jun 26, 2024
1 parent 22be6cf commit 21c95e7
Show file tree
Hide file tree
Showing 21 changed files with 272 additions and 187 deletions.
25 changes: 14 additions & 11 deletions docs/data/material/components/autocomplete/CheckboxesTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ export default function CheckboxesTags() {
options={top100Films}
disableCloseOnSelect
getOptionLabel={(option) => option.title}
renderOption={(props, option, { selected }) => (
<li {...props}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
{option.title}
</li>
)}
renderOption={(props, option, { selected }) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
{option.title}
</li>
);
}}
style={{ width: 500 }}
renderInput={(params) => (
<TextField {...params} label="Checkboxes" placeholder="Favorites" />
Expand Down
25 changes: 14 additions & 11 deletions docs/data/material/components/autocomplete/CheckboxesTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ export default function CheckboxesTags() {
options={top100Films}
disableCloseOnSelect
getOptionLabel={(option) => option.title}
renderOption={(props, option, { selected }) => (
<li {...props}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
{option.title}
</li>
)}
renderOption={(props, option, { selected }) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
{option.title}
</li>
);
}}
style={{ width: 500 }}
renderInput={(params) => (
<TextField {...params} label="Checkboxes" placeholder="Favorites" />
Expand Down
32 changes: 20 additions & 12 deletions docs/data/material/components/autocomplete/CountrySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ export default function CountrySelect() {
options={countries}
autoHighlight
getOptionLabel={(option) => option.label}
renderOption={(props, option) => (
<Box component="li" sx={{ '& > img': { mr: 2, flexShrink: 0 } }} {...props}>
<img
loading="lazy"
width="20"
srcSet={`https://flagcdn.com/w40/${option.code.toLowerCase()}.png 2x`}
src={`https://flagcdn.com/w20/${option.code.toLowerCase()}.png`}
alt=""
/>
{option.label} ({option.code}) +{option.phone}
</Box>
)}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<Box
key={key}
component="li"
sx={{ '& > img': { mr: 2, flexShrink: 0 } }}
{...optionProps}
>
<img
loading="lazy"
width="20"
srcSet={`https://flagcdn.com/w40/${option.code.toLowerCase()}.png 2x`}
src={`https://flagcdn.com/w20/${option.code.toLowerCase()}.png`}
alt=""
/>
{option.label} ({option.code}) +{option.phone}
</Box>
);
}}
renderInput={(params) => (
<TextField
{...params}
Expand Down
32 changes: 20 additions & 12 deletions docs/data/material/components/autocomplete/CountrySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ export default function CountrySelect() {
options={countries}
autoHighlight
getOptionLabel={(option) => option.label}
renderOption={(props, option) => (
<Box component="li" sx={{ '& > img': { mr: 2, flexShrink: 0 } }} {...props}>
<img
loading="lazy"
width="20"
srcSet={`https://flagcdn.com/w40/${option.code.toLowerCase()}.png 2x`}
src={`https://flagcdn.com/w20/${option.code.toLowerCase()}.png`}
alt=""
/>
{option.label} ({option.code}) +{option.phone}
</Box>
)}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<Box
key={key}
component="li"
sx={{ '& > img': { mr: 2, flexShrink: 0 } }}
{...optionProps}
>
<img
loading="lazy"
width="20"
srcSet={`https://flagcdn.com/w40/${option.code.toLowerCase()}.png 2x`}
src={`https://flagcdn.com/w20/${option.code.toLowerCase()}.png`}
alt=""
/>
{option.label} ({option.code}) +{option.phone}
</Box>
);
}}
renderInput={(params) => (
<TextField
{...params}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ export default function FreeSoloCreateOption() {
// Regular option
return option.title;
}}
renderOption={(props, option) => <li {...props}>{option.title}</li>}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
{option.title}
</li>
);
}}
sx={{ width: 300 }}
freeSolo
renderInput={(params) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ export default function FreeSoloCreateOption() {
// Regular option
return option.title;
}}
renderOption={(props, option) => <li {...props}>{option.title}</li>}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
{option.title}
</li>
);
}}
sx={{ width: 300 }}
freeSolo
renderInput={(params) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export default function FreeSoloCreateOptionDialog() {
selectOnFocus
clearOnBlur
handleHomeEndKeys
renderOption={(props, option) => <li {...props}>{option.title}</li>}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
{option.title}
</li>
);
}}
sx={{ width: 300 }}
freeSolo
renderInput={(params) => <TextField {...params} label="Free solo dialog" />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export default function FreeSoloCreateOptionDialog() {
selectOnFocus
clearOnBlur
handleHomeEndKeys
renderOption={(props, option) => <li {...props}>{option.title}</li>}
renderOption={(props, option) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
{option.title}
</li>
);
}}
sx={{ width: 300 }}
freeSolo
renderInput={(params) => <TextField {...params} label="Free solo dialog" />}
Expand Down
93 changes: 48 additions & 45 deletions docs/data/material/components/autocomplete/GitHubLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,51 +214,54 @@ export default function GitHubLabel() {
disableCloseOnSelect
renderTags={() => null}
noOptionsText="No labels"
renderOption={(props, option, { selected }) => (
<li {...props}>
<Box
component={DoneIcon}
sx={{ width: 17, height: 17, mr: '5px', ml: '-2px' }}
style={{
visibility: selected ? 'visible' : 'hidden',
}}
/>
<Box
component="span"
sx={{
width: 14,
height: 14,
flexShrink: 0,
borderRadius: '3px',
mr: 1,
mt: '2px',
}}
style={{ backgroundColor: option.color }}
/>
<Box
sx={(t) => ({
flexGrow: 1,
'& span': {
color: '#8b949e',
...t.applyStyles('light', {
color: '#586069',
}),
},
})}
>
{option.name}
<br />
<span>{option.description}</span>
</Box>
<Box
component={CloseIcon}
sx={{ opacity: 0.6, width: 18, height: 18 }}
style={{
visibility: selected ? 'visible' : 'hidden',
}}
/>
</li>
)}
renderOption={(props, option, { selected }) => {
const { key, ...optionProps } = props;
return (
<li key={key} {...optionProps}>
<Box
component={DoneIcon}
sx={{ width: 17, height: 17, mr: '5px', ml: '-2px' }}
style={{
visibility: selected ? 'visible' : 'hidden',
}}
/>
<Box
component="span"
sx={{
width: 14,
height: 14,
flexShrink: 0,
borderRadius: '3px',
mr: 1,
mt: '2px',
}}
style={{ backgroundColor: option.color }}
/>
<Box
sx={(t) => ({
flexGrow: 1,
'& span': {
color: '#8b949e',
...t.applyStyles('light', {
color: '#586069',
}),
},
})}
>
{option.name}
<br />
<span>{option.description}</span>
</Box>
<Box
component={CloseIcon}
sx={{ opacity: 0.6, width: 18, height: 18 }}
style={{
visibility: selected ? 'visible' : 'hidden',
}}
/>
</li>
);
}}
options={[...labels].sort((a, b) => {
// Display the selected labels first.
let ai = value.indexOf(a);
Expand Down
Loading

0 comments on commit 21c95e7

Please sign in to comment.