Skip to content

[Select][material-ui] Respect default prevented event on click (do not close) #46458

Description

@pcorpet

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

Metadata

Metadata

Assignees

Labels

duplicateThis issue or pull request already exists.scope: selectChanges related to the select.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions