Material-ui: [Autocomplete] Prevent backspace key from deleting selected chips when using multiple values

Created on 20 May 2020  路  3Comments  路  Source: mui-org/material-ui

Summary 馃挕

There should be a way to disable or customise the current behaviour of the backspace key in the autocomplete component (when using multiple values). Currently, pressing backspace will delete the rightmost selected chip. Holding backspace will quickly clear everything. For my use case, this could negatively effect the user experience.

Autocomplete question

All 3 comments

@lukefisklennon One option is to control the value and filter events. The second is to help us get #19887 down the finish line.

@oliviertassinari Thanks for the quick reply, that worked!

Someone emailed me asking about what code I used to get it working, so here's a rough outline of what I did if anyone needs it:

<Autocomplete
    // other props...
    renderInput={(params) => (
        <TextField
            {...params}
            // other props...
            onChange={(event) => {/* handle event... */}} 
            onKeyDown={(event: any) => {
                if (event.key === 'Backspace') {
                    event.stopPropagation();
                }
            }}
        />
    )}
/>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

pola88 picture pola88  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

revskill10 picture revskill10  路  3Comments

sys13 picture sys13  路  3Comments