Summary
When using event.preventDefault() inside a MenuItem's onClick callback, it should not change the value nor close the menu.
Examples
Clicking the "load more" option below could keep the Select menu open.
<Select value={age} label="Age" onChange={handleChange}>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
<MenuItem
onClick={e => {
e.preventDefault()
loadMoreAgeOptions()
}>load more ...</MenuItem>
</Select>
There is a workaround where I can keep the open state controlled and decide to ignore the close, however this seems a good use of the preventDefault feature while making it way more streamlined to implement.
Motivation
No response
Search keywords: Select preventDefault
Summary
When using
event.preventDefault()inside aMenuItem'sonClickcallback, it should not change the value nor close the menu.Examples
Clicking the "load more" option below could keep the Select menu open.
There is a workaround where I can keep the open state controlled and decide to ignore the close, however this seems a good use of the
preventDefaultfeature while making it way more streamlined to implement.Motivation
No response
Search keywords: Select preventDefault