angular - 垫选择滚动不跳转到选定的垫选项
问题描述
作为用户,当我从键盘键入选项时,滚动条不会位于突出显示的项目上。此外,当我选择复选框时,滚动条会滚动到其他位置,而不是坚持选定的选项。
代码是
<form >
<mat-form-field appearance="outline" floatLabel="never" class="some-class">
<mat-select #multiselect [compareWith]="somefn" disableOptionCentering="true" disableRipple="true" panelClass=some-class" placeholder="{{label}}" [formControl]="control" multiple class="some-class" (selectionChange)="somefn()">
<mat-select-trigger>
<span *ngIf="control.value?.length == allSelectedNum; else otherBlock">
ALL
</span>
<ng-template #otherblock>
##more code
</ng-template>
</mat-select-trigger>
<mat-option #allSelected [value]="'0'" (click)="someclickfn()">Select/Deselect All</mat-option>
<mat-option *ngFor="let apple of appleList" [value]="apple" (click)="someotherclk(apple)">{{apple.name}}</mat-option>
</mat-select>
</mat-form-field>
</form>
解决方案
我有同样的问题。就我而言,原因是我改变了我的垫子选项的高度与原始垫子选项相比,现在在选择项目材料时试图集中或将所选项目放在某个位置,但由于所有下拉列表的大小改变,我认为它正在计算位置错误并滚动到完全不同的项目。
这甚至可以在材料示例 https://stackblitz.com/angular/lvlxpvkrnlk?file=app%2Fselect-optgroup-example.ts上重现
只需将 mat-option 的样式更改为类似的样式
.option-style {
height: 15px !important;
font-size: 12px !important;
}
并在中间添加更多项目并尝试在中间选择一些东西在这里我试图模拟情况: https ://stackblitz.com/edit/angular-lmkqjv?file=app%2Fselect-optgroup-example.css
推荐阅读
- express - 带生成的 Nuxt 服务器中间件
- c++ - 如何正确使用带有子目录的 automake/autoconf?
- ruby-on-rails - active admin many to many show index PG::UndefinedColumn: ERROR: column cases.product_id does not exist
- javascript - 未捕获的类型错误:无法读取未定义的属性“toLowerCase”(WordPress)
- java - 使用 Spring Data JPA 时如何避免 DETACHED 对象或未初始化的 Hibernate 代理?
- numpy - 如何在 keras lambda 层中使用 tf.py_func 来包装 python 代码。ValueError:应定义 Dense 输入的最后一个维度。没有找到
- java - 应用程序崩溃卡在启动画面上 - 返回按钮显示错误
- css - 如何在 Google Page Speed Insights 中删除“预加载密钥请求错误”
- javascript - 用户登录的持久性与 jwt 令牌和重新加载后的反应
- c++ - 左值和右值引用可以合二为一吗?