angular - 如何在 Angular 中为 mat-chip-list 的输入字段添加水平滚动?
问题描述
我最近开始学习 Angular 和 Angular Material,但我想不出一种方法来将滚动条添加到 mat-chip-list 的扩展输入字段中。我的输入字段是可编辑的,同时还使用自动完成列表来填充数据。我尝试过类似的答案,要求您编辑 CSS,但没有一个对我有用。我需要芯片以水平滚动显示在一行中。现在,输入字段的大小刚刚增加以容纳芯片。
我的代码片段:
<!--Keyword section-->
<mat-form-field class="ranking-chip-list">
<mat-chip-list #chipList>
<mat-chip *ngFor="let keyword of keywords" [selectable]="selectable" [removable]="removable"
(removed)="remove(keyword)">
{{keyword}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input placeholder="Type your keywords to sort resumes..." #keywordInput [formControl]="keywordCtrl"
[matAutocomplete]="auto" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" (matChipInputTokenEnd)="add($event)" />
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let keyword of filteredKeywords | async" [value]="keyword">
{{keyword}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
<!--Keyword section ends-->
如果我还应该链接 TypeScript 代码,请告诉我。
解决方案
只需禁用芯片列表持有人的 flex-wrap
.mat-chip-list-wrapper {
flex-wrap: nowrap;
overflow-x: auto;
}
请注意,如果您在组件中有一些封装 - 您需要使用一些深度选择器或写入 styles.scss,也许这就是您尝试的 CSS 解决方案不起作用的原因,因为 css 是非常明显的单行解决方案
推荐阅读
- java - 为什么 MigLayout 中的这个滚动窗格一直向右扩展?
- python - 确定全局异常处理程序中的错误消息,而不是它崩溃的位置
- reactjs - Chakra UI Modal 无法正常工作
- attributes - 我们如何生成具有多个附加输入字段的属性组合
- node.js - 重置密码令牌 nodejs 和 express, throw er; // 未处理的“错误”事件 ^ 错误:回调已被调用
- firebase - 使用 expo 权限反应原生 firebase 推送通知
- c++ - 我如何解决这个没有匹配的函数来调用'stoi(int&)'|
- reactjs - 如何将 webpack 配置为代码拆分小型静态反应页面
- reactjs - React JS 登录和路由器未按预期工作
- android - 为什么 FingerprintManager.AuthenticationCallback 在前台服务中没有响应?