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

[Autocompete][material] Fix value overflow when disableClearable is used #34053

Merged
merged 3 commits into from Aug 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.js
Expand Up @@ -144,7 +144,11 @@ const AutocompleteRoot = styled('div', {
},
},
[`& .${outlinedInputClasses.root}.${inputBaseClasses.sizeSmall}`]: {
padding: 6,
// Don't specify paddingRight, as it overrides the default value set when there is only
// one of the popup or clear icon as the specificity is equal so the latter one wins
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 6,
[`& .${autocompleteClasses.input}`]: {
padding: '2.5px 4px 2.5px 6px',
},
Expand Down
121 changes: 121 additions & 0 deletions test/regressions/fixtures/Autocomplete/SizeSmallValueOverflow.js
@@ -0,0 +1,121 @@
import * as React from 'react';
import Stack from '@mui/material/Stack';
import Chip from '@mui/material/Chip';
import Autocomplete from '@mui/material/Autocomplete';
import TextField from '@mui/material/TextField';

const movies = [
{
title: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
];

export default function Sizes() {
return (
<Stack spacing={2} sx={{ width: 300 }}>
<Autocomplete
id="size-small-outlined"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={movies[0]}
disableClearable
renderInput={(params) => <TextField {...params} label="Movie" placeholder="Favorites" />}
/>
<Autocomplete
multiple
id="size-small-outlined-multi"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={[movies[0]]}
disableClearable
renderInput={(params) => <TextField {...params} label="Movie" placeholder="Favorites" />}
/>
<Autocomplete
id="size-small-outlined"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={movies[0]}
renderInput={(params) => <TextField {...params} label="Movie" placeholder="Favorites" />}
/>
<Autocomplete
multiple
id="size-small-outlined-multi"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={[movies[0]]}
renderInput={(params) => <TextField {...params} label="Movie" placeholder="Favorites" />}
/>
<Autocomplete
id="size-small-standard"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={movies[0]}
disableClearable
renderInput={(params) => (
<TextField {...params} variant="standard" label="Movies" placeholder="Favorites" />
)}
/>
<Autocomplete
multiple
id="size-small-standard-multi"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={[movies[0]]}
disableClearable
renderInput={(params) => (
<TextField {...params} variant="standard" label="Movies" placeholder="Favorites" />
)}
/>
<Autocomplete
id="size-small-filled"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={movies[0]}
disableClearable
renderTags={(value, getTagProps) =>
value.map((option, index) => (
<Chip
variant="outlined"
label={option.title}
size="small"
{...getTagProps({ index })}
/>
))
}
renderInput={(params) => (
<TextField {...params} variant="filled" label="Movies" placeholder="Favorites" />
)}
/>
<Autocomplete
multiple
id="size-small-filled-multi"
size="small"
options={movies}
getOptionLabel={(option) => option.title}
defaultValue={[movies[0]]}
disableClearable
renderTags={(value, getTagProps) =>
value.map((option, index) => (
<Chip
variant="outlined"
label={option.title}
size="small"
{...getTagProps({ index })}
/>
))
}
renderInput={(params) => (
<TextField {...params} variant="filled" label="Movies" placeholder="Favorites" />
)}
/>
</Stack>
);
}