admin管理员组文章数量:1418637
Actually, in a mat-chip, we need to press Enter
to be able to add a new element in the list.
I'd like to have the space
, comma
and tab
to have the same effect.
How would this be doable?
Here's the code :
<mat-form-field>
<mat-label>Emails</mat-label>
<mat-chip-grid #chipGrid aria-label="Enter email" formControlName="emails">
@for (keyword of keywords$(); track keyword) {
<mat-chip-row (removed)="removeKeyword(keyword)">
{{keyword}}
<button matChipRemove aria-label="'remove ' + keyword">
<mat-icon>cancel</mat-icon>
</button>
</mat-chip-row>
}
</mat-chip-grid>
<input
[placeholder]="'EMAIL' | translate"
[matChipInputFor]="chipGrid"
(matChipInputTokenEnd)="add($event)"
/>
</mat-form-field>
Actually, in a mat-chip, we need to press Enter
to be able to add a new element in the list.
I'd like to have the space
, comma
and tab
to have the same effect.
How would this be doable?
Here's the code :
<mat-form-field>
<mat-label>Emails</mat-label>
<mat-chip-grid #chipGrid aria-label="Enter email" formControlName="emails">
@for (keyword of keywords$(); track keyword) {
<mat-chip-row (removed)="removeKeyword(keyword)">
{{keyword}}
<button matChipRemove aria-label="'remove ' + keyword">
<mat-icon>cancel</mat-icon>
</button>
</mat-chip-row>
}
</mat-chip-grid>
<input
[placeholder]="'EMAIL' | translate"
[matChipInputFor]="chipGrid"
(matChipInputTokenEnd)="add($event)"
/>
</mat-form-field>
Share
Improve this question
edited Jan 29 at 14:42
Raphaël Balet
asked Jan 29 at 14:07
Raphaël BaletRaphaël Balet
8,6878 gold badges64 silver badges111 bronze badges
1
|
1 Answer
Reset to default -1Thx @javaa for his comment, the following can be achieved with [matChipInputSeparatorKeyCodes]="separatorKeys"
Here's the code
import { COMMA, ENTER, SPACE, TAB } from '@angular/cdk/keycodes';
separatorKeys = [ENTER, COMMA, SPACE, TAB];
<input
[matChipInputSeparatorKeyCodes]="separatorKeys"
[placeholder]="'EMAIL' | translate"
[matChipInputFor]="chipGrid"
(matChipInputTokenEnd)="add($event)"
/>
本文标签: javascriptAngular matchipuse space and tab to enter a new inputStack Overflow
版权声明:本文标题:javascript - Angular mat-chip, use space and tab to enter a new input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745293006a2651911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
separatorKeyCodes
. The example code already contains it: material.angular.io/components/chips/…[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
– jabaa Commented Jan 29 at 14:14