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.

mat-chip selected no matter what

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

[selectable]=“false” should works properly.

What is the current behavior?

[selectable]=“false” doesn’t work

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV

    <mat-form-field>
      <mat-chip-list #phraseList class="mat-chip-list-stacked" ngDefaultControl formControlName="phrases" [selectable]="false">
        <mat-chip *ngFor="let phrase of phrases.value" [selectable]="false" [selected]="false" [removable]="true" [disabled]="true">
          <span fxFlex="100%">{{ phrase }}</span>
        </mat-chip>
        <input class="w-100" fxFlex="0%" placeholder="Phrase" [matChipInputFor]="phraseList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
          [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addPhrase($event)" />
      </mat-chip-list>
    </mat-form-field>

    this.form = new FormGroup({
      phrases: new FormControl(new Array<string>())
    });

    addPhrase(e: MatChipInputEvent): void {
        const input = e.input;
        const value = e.value;
        const phrases = this.phrases.value;

        if ((value || '').trim()) {
          phrases.push(value.trim());
          this.phrases.setValue(phrases);
        }

        if (input) {
          input.value = '';
        }
    }

    get phrases() {
        return this.form.get('phrases');
    }

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

6.0.4

Is there anything else we should know?

screenshot from 2018-06-19 13-03-19

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
tinayuangaocommented, Jun 19, 2018

@Corsseir Could you please provide a stackblitz reproduction? I cannot reproduce this issue

[selectable]="false" is working properly here: https://stackblitz.com/edit/angular-wcfsvk?file=app%2Fchips-input-example.html

2reactions
Ferrin13commented, Aug 9, 2018

@tinayuangao This is what appears for me what I click on a chip (or tab to it) in Chrome 68.0.3440.84 and Firefox 61.0.2 for the stackblitz you provided. Toggling the selectable flag has no visual effect when selecting/de-selecting the chip.

Is [selectable] only supposed to cause the selected state to be ignored? Reading the documentation, it does not explicitly state that the chip will not be selectable visually, though that seems like a logical conclusion of not being selectable.

selectablebroken selectablebroken2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chips | Angular Material
Users can move through the chips using the arrow keys and select/deselect them with space. Chips also gain focus when clicked, ensuring keyboard...
Read more >
Angular Material MatChipList does not fire change, nor select ...
Tried using (click) instead of selectionChange event and it worked. I had several similar issues while working with material components.
Read more >
Chips | Angular Material
An extension of the MatChip component that supports chip selection. ... When a chip is not selectable, changes to its selected state are...
Read more >
material multi select with search - You.com - You.com
I'm trying to create a custom multi select component, based on the angular-material select component (v10), with virtual-scroll and a custom search input...
Read more >
Angular Material: How to Bind Chips to a Form Field
Because that's not what the docs tell you to do. Also, the form control name is added to the <mat-chip-list> element. You might...
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