I'm using the Select inside a div component:
<div className="custom-filter custom-filter-data">
<DateRangeIcon className="search-icon"/>
<FormControl variant='standard' ref={addrRef} className=
{classes.formControl}>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
defaultValue=""
onFocus={(e) => {addrRef.current.focus()}}
displayEmpty
>
<MenuItem value="" disabled>
Seleziona data
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
//other components
</div>
css container
.custom-filter:focus-within{
color: #495057;
background-color: #fff;
border-color: #80bdff;
outline: 0;
box-shadow: 0 0 0 0.2rem rgb(0 123 255 / 25%);
}
I need to trigger the focus on the select when the select input is clicked in order to leverage :focus-within styling of the parent container. Now the parent :focus-within is working just onChange event (when I select the MenuItem). as you can see, I've tried with useRef() but is not working... It seems that when a user clicks on the input of the select, it blocks all the other focus...
https://codesandbox.io/s/react-material-ui-select-forked-8msbu?file=/src/index.js