Skip to content

Commit c44cb3f

Browse files
github-actions[bot]TahaRhidouaniZeeshanTamboli
authored
[material-ui][Autocomplete] Improve design when there's a start adornment for small autocomplete (@TahaRhidouani) (#42176)
Co-authored-by: Taha Rhidouani <[email protected]> Co-authored-by: ZeeshanTamboli <[email protected]>
1 parent 9bc4fc4 commit c44cb3f

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

packages/mui-material/src/Autocomplete/Autocomplete.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,11 @@ const AutocompleteRoot = styled('div', {
8787
];
8888
},
8989
})({
90-
[`&.${autocompleteClasses.focused} .${autocompleteClasses.clearIndicator}`]: {
91-
visibility: 'visible',
92-
},
93-
/* Avoid double tap issue on iOS */
94-
'@media (pointer: fine)': {
95-
[`&:hover .${autocompleteClasses.clearIndicator}`]: {
96-
visibility: 'visible',
97-
},
98-
},
9990
[`& .${autocompleteClasses.tag}`]: {
10091
margin: 3,
10192
maxWidth: 'calc(100% - 6px)',
10293
},
10394
[`& .${autocompleteClasses.inputRoot}`]: {
104-
flexWrap: 'wrap',
10595
[`.${autocompleteClasses.hasPopupIcon}&, .${autocompleteClasses.hasClearIcon}&`]: {
10696
paddingRight: 26 + 4,
10797
},
@@ -113,6 +103,23 @@ const AutocompleteRoot = styled('div', {
113103
minWidth: 30,
114104
},
115105
},
106+
[`&.${autocompleteClasses.focused}`]: {
107+
[`& .${autocompleteClasses.clearIndicator}`]: {
108+
visibility: 'visible',
109+
},
110+
[`& .${autocompleteClasses.input}`]: {
111+
minWidth: 0,
112+
},
113+
},
114+
/* Avoid double tap issue on iOS */
115+
'@media (pointer: fine)': {
116+
[`&:hover .${autocompleteClasses.clearIndicator}`]: {
117+
visibility: 'visible',
118+
},
119+
[`&:hover .${autocompleteClasses.input}`]: {
120+
minWidth: 0,
121+
},
122+
},
116123
[`& .${inputClasses.root}`]: {
117124
paddingBottom: 1,
118125
'& .MuiInput-input': {
@@ -215,6 +222,14 @@ const AutocompleteRoot = styled('div', {
215222
},
216223
},
217224
},
225+
{
226+
props: { multiple: true },
227+
style: {
228+
[`& .${autocompleteClasses.inputRoot}`]: {
229+
flexWrap: 'wrap',
230+
},
231+
},
232+
},
218233
],
219234
});
220235

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as React from 'react';
2+
import Autocomplete from '@mui/material/Autocomplete';
3+
import SvgIcon from '@mui/material/SvgIcon';
4+
import TextField from '@mui/material/TextField';
5+
6+
const movies = [
7+
{
8+
label: 'The Lord of the Rings: The Two Towers',
9+
year: 2002,
10+
},
11+
];
12+
13+
export default function SmallAutocompleteWithStartAdornment() {
14+
return (
15+
<Autocomplete
16+
options={movies}
17+
value={movies[0]}
18+
sx={{ width: 120, mt: 2 }}
19+
renderInput={(params) => (
20+
<TextField
21+
{...params}
22+
label="Autocomplete"
23+
InputProps={{
24+
...params.InputProps,
25+
startAdornment: (
26+
<SvgIcon>
27+
<svg
28+
xmlns="http://www.w3.org/2000/svg"
29+
fill="none"
30+
viewBox="0 0 24 24"
31+
strokeWidth={1.5}
32+
stroke="currentColor"
33+
>
34+
<path
35+
strokeLinecap="round"
36+
strokeLinejoin="round"
37+
d="M4.5 12a7.5 7.5 0 0015 0m-15 0a7.5 7.5 0 1115 0m-15 0H3m16.5 0H21m-1.5 0H12m-8.457 3.077l1.41-.513m14.095-5.13l1.41-.513M5.106 17.785l1.15-.964m11.49-9.642l1.149-.964M7.501 19.795l.75-1.3m7.5-12.99l.75-1.3m-6.063 16.658l.26-1.477m2.605-14.772l.26-1.477m0 17.726l-.26-1.477M10.698 4.614l-.26-1.477M16.5 19.794l-.75-1.299M7.5 4.205L12 12m6.894 5.785l-1.149-.964M6.256 7.178l-1.15-.964m15.352 8.864l-1.41-.513M4.954 9.435l-1.41-.514M12.002 12l-3.75 6.495"
38+
/>
39+
</svg>
40+
</SvgIcon>
41+
),
42+
}}
43+
/>
44+
)}
45+
/>
46+
);
47+
}

0 commit comments

Comments
 (0)