question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dalexander-trccommented, Jun 18, 2020

The solution described at StackOverflow worked for me, currently using Angular 8.

HTML <input type="text" [matAutocomplete]="auto" [matChipInputFor]="chipList" (keydown.backspace)="onBackspaceKeydown($event)">

TS public onBackspaceKeydown(event) { event.stopImmediatePropagation(); }

1reaction
mmalerbacommented, Jun 18, 2020

Yeah, that’s what I had in mind

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to not remove the tag input chip when hitting the last ...
The problem which I am facing is that whenever I hit backspace for the last character, it removes the previous tag as well....
Read more >
Chips | Angular Material
Unlike other chips, the user can focus on disabled chip options inside a MatChipListbox. The user cannot click disabled chips.
Read more >
angular/material
Called by the MatChipList when the DELETE or\n * BACKSPACE keys are pressed.\n *\n * Informs any listeners of the removal request. Does...
Read more >
Angular Material - Demos > Chips
You can use the Semicolon, Enter, or Comma keys to trigger chip creation. test@example.com. Remove. Press delete to remove this chip.
Read more >
Angular Material Chips
When disabled, chips are neither selectable nor noticeable. Chip Input. The MatChipInput directive will be used with a chip list to streamline the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found