angular - Detect keyboard navigation in angular material mat-selection-list
问题描述
I want to make some actions When navigating between items using keyboard arrows.
Is there any event should i implemented? The selectionChange is fired by clicking ENTER but i want to activate the function while navigating by arrows.
<mat-selection-list #list (selectionChange)="selectionChange($event, list.selectedOptions)">
<mat-list-option (mouseenter)="showEditIcon(true, i)" (mouseleave)="showEditIcon(false, i)"
*ngFor="let lotItem of lotList; let i = index;"
(click)="showLotDetails(lotItem, i)"
[value]='lotItem'>
解决方案
您可以使用您的keydown
键盘事件mat-selection-list
来调用您的selectionChange()
方法。您需要同时添加(keydown.arrowup)
和(keydown.arrowdown)
事件处理程序。
<mat-selection-list #list
(selectionChange)="selectionChange($event, list.selectedOptions)"
(keydown.arrowup)="selectionChange($event)"
(keydown.arrowdown)="selectionChange($event)">
<mat-list-option (mouseenter)="showEditIcon(true, i)" (mouseleave)="showEditIcon(false, i)"
*ngFor="let lotItem of lotList; let i = index;"
(click)="showLotDetails(lotItem, i)"
[value]='lotItem'>
这是一个StackBlitz 演示。
推荐阅读
- wordpress - 如何在 Wordress 中为类别使用自定义 url?
- java - 使用 Windows 计算机在 Dr.java 上调试的问题
- sql - SQL BigQuery - 比较两个表的总计数
- r - 如何将 NA 替换为稍后输入的具有相同 ID 和日期的值
- python - Fiddler 没有从 locust.io v1.1.1 捕获流量
- ruby - 宝石试图告诉我的这些错误是什么?
- node.js - npm 错误!在运行 npm install -g @angular/cli 时解析“...ain”附近的 JSON 输入意外结束:“src/index.js”
- java - Apache CLI 选项中的空格
- twitter - 如果 Twitter 认为推文有害,如何检索?
- java - 无法访问 androidx.savedstate.SavedStateRegistryOwner