AngularngbDropdown:键盘导航不起作用
创始人
2024-10-28 16:30:24
0

要使Angular ngbDropdown的键盘导航正常工作,你需要在templateRef和ngbDropdown实例之间使用ng-container指令来设置tabindex,然后使用@ViewChild装饰器引用ngbDropdown指令,最后在NgAfterViewInit生命周期钩子中调用dropdown.focusFirst()方法即可。

HTML模板:


  



组件类:

import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-dropdown-example',
  templateUrl: './dropdown-example.component.html'
})
export class DropdownExampleComponent implements AfterViewInit {
  dropdownItems = [
    'Action',
    'Another action',
    'Something else is here'
  ];

  @ViewChild('myDrop', { static: false }) dropdown: NgbDropdown;

  ngAfterViewInit() {
    this.dropdown.focusFirst();
  }
}

相关内容

热门资讯

透视模块!wepoker国外版... 透视模块!wepoker国外版透视(AApoker万能)切实真的是有辅助插件(哔哩哔哩)1)wepo...
透视资料!德州来玩辅助器(We... 透视资料!德州来玩辅助器(WePoKer软件)果然真的有辅助攻略(哔哩哔哩)一、德州来玩辅助器可以开...
透视阶段!竞技联盟破解版最新版... 透视阶段!竞技联盟破解版最新版(HHpoker软件)竟然真的有辅助攻略(哔哩哔哩)一、竞技联盟破解版...
透视攻略!werplan外开挂... 透视攻略!werplan外开挂(WePoKer内容)本来存在有辅助方法(哔哩哔哩)1、werplan...
透视项目!wepoker透视破... 透视项目!wepoker透视破解版(HHpoker内部)切实真的是有辅助教程(哔哩哔哩)1)wepo...
透视操作!wepoker有用吗... 透视操作!wepoker有用吗(WePoKer内容)总是是有辅助app(哔哩哔哩)1、wepoker...
透视项目!哈糖大菠萝怎么挂(W... 透视项目!哈糖大菠萝怎么挂(WPK软件)一直是真的有辅助方法(哔哩哔哩)1、玩家可以在哈糖大菠萝怎么...
透视要领!哈糖大菠萝助手(We... 您好,哈糖大菠萝助手这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
透视步骤!德州私人局怎么透视(... 透视步骤!德州私人局怎么透视(WePoKer app)确实有辅助方法(哔哩哔哩)1、每一步都需要思考...
透视总结!wepoker免费脚... 透视总结!wepoker免费脚本咨询(WePoKer代打)一贯存在有辅助工具(哔哩哔哩)1、wepo...