Skip to content

[MatChipList] Disable last chip focus when pressing BACKSPACE with empty input #18659

Closed
@gioragutt

Description

@gioragutt

Feature Description

By default, when you have chips, and your input is empty and focused,
When your press BACKSPACE, the last chip will be selected.

The feature I'm looking for is that this behaviour will be behind a flag, which would obviously be enabled/disabled by default (whatever keeps the current behaviour the default), and when the flag is toggled - pressing BACKSPACE when the input is empty would not select the last chip.

Use Case

The use case for this behaviour is when you have chips, and the user deletes whatever input he put in so far, eventually when the input is cleared, the chips will get focused and will be deleted.

This something that may be problematic for some users in some cases, and as far as I can see, it's not something that should be too hard to implement.

Side Note

I've been looking at docs and code to try to disable this behaviour myself, but I couldn't find a way (without changing code).

I tried calling preventDefault and stopPropagation on the events from keyup, keydown and input events on the input[matChipInputFor] input, but I guess that the MatChipList subscription to those events takes precedence over the user subscription (probably due to subscription order), and calling preventDefault/stopPropagation on the event is just too late.

If you can help find a way to achieve this behaviour without changing the component, this would help me a lot.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: material/chipsfeatureThis issue represents a new feature or feature request rather than a bug or bug fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions