angular-material - MatChipList 选项卡导航

标签 angular-material

我有一个包含芯片列表的 mat-form-field 和另一个包含任何其他类型输入的 mat-form-field。我希望能够从芯片列表导航到输入字段并进入以下 mat-form-fields,但似乎不支持这种行为。有没有人可以解决此问题,以便能够使用选项卡导航此组件?

<mat-form-field class="example-chip-list">
  <mat-chip-list #chipList>
    <mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
             [removable]="removable" (removed)="remove(fruit)">
      {{fruit.name}}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>
    <input placeholder="New fruit..."
           [matChipInputFor]="chipList"
           [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
           [matChipInputAddOnBlur]="addOnBlur"
           (matChipInputTokenEnd)="add($event)">
  </mat-chip-list>
</mat-form-field>
<mat-form-field>
  <input placeholder="Another unrelated field" matInput>
</mat-form-field>

示例:https://stackblitz.com/edit/angular-ixswwc?file=app/chips-input-example.html

最佳答案

发生焦点无限循环是因为 <input>位于 <mat-chip-list> 的内部

可以通过以下方法解决

<mat-form-field class="example-chip-list">
  <mat-chip-list #chipList>
    <mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
             [removable]="removable" (removed)="remove(fruit)">
      {{fruit.name}}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>
    
  </mat-chip-list>
<input placeholder="New fruit..."
           [matChipInputFor]="chipList"
           [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
           [matChipInputAddOnBlur]="addOnBlur"
           (matChipInputTokenEnd)="add($event)">
</mat-form-field>
<mat-form-field>
  <input placeholder="Another unrelated field" matInput>
</mat-form-field>

关于angular-material - MatChipList 选项卡导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52336690/

相关文章:

html - 如何将 Material 图标和标题文本对齐在同一行?

Angular Material DatePicker - 错误 : MdDatepicker: No provider found for DateAdapter

angular - 如何使 mat-icon 以 Angular 禁用?

javascript - 如何使用 jquery ui sortable 对使用 Material 设计创建的 Angular 选项卡进行排序?

angularjs - 如何为 Angular Material 的 md-select 选择框添加边框?

Angular : how to trigger bindings manually?

angular - 与简单的媒体查询相比,使用 Angular Material BreakpointObserver API 有什么好处?

javascript - 如何制作可主题化的 Angular Material NPM 模块?

带有选择的属性的 Angular i18n

html - Md-内容不滚动