我需要在html输入元素(搜索域)上使用键盘激活光标.
它在使用鼠标时工作得很好,但由于WCAG的要求,我需要使用键盘使其完全工作.
https://stackblitz.com/edit/angular-dukfxf?file=src%2Fapp%2Fapp.component.ts个
我几乎try 了所有方法,从定制的js代码到Angular 指令.
有什么 idea 吗?
我需要在html输入元素(搜索域)上使用键盘激活光标.
它在使用鼠标时工作得很好,但由于WCAG的要求,我需要使用键盘使其完全工作.
https://stackblitz.com/edit/angular-dukfxf?file=src%2Fapp%2Fapp.component.ts个
我几乎try 了所有方法,从定制的js代码到Angular 指令.
有什么 idea 吗?
您可以执行以下操作:
openedChange
from mat-select<mat-select (openedChange)="focus()">
<input
...
#exampleInput
/>
</mat-select>
focus()
in your component and it would workexport class AppComponent {
@ViewChild('exampleInput') searchElement: ElementRef;
...
focus() {
setTimeout(() => {
this.searchElement.nativeElement.focus();
}, 0);
}
}