【问题标题】:how to identify button element is focused如何识别按钮元素是焦点
【发布时间】:2018-04-12 09:42:24
【问题描述】:
<div class="text-right">
  <th-input-group [(ngModel)]="filter" (keyup)="onInput($event, false, true)" 
       id="filterInput" #filterInput 
       [placeholder]="searchFilterPlaceHolder"></th-input-group>

   <th-button id="btnPopClose" #btnPopClose type="button" class="btn btn-default" 
   (click)="onFavPopupClose()">{{closeButtonText}}
   </th-button>
</div>

我的自定义弹出模式中有上述 html 输入和按钮元素。

不在组件中我正在使用 HostListener 来识别 Tab 键按下。

@ViewChild('filterInput') elementfilterInputRef: any;
@ViewChild('btnPopClose') elementCloseButtonRef: any;

@HostListener('keydown.tab')
onTab() {
if(this.elementCloseButtonRef.hasFocued || 
this.elementfilterInputRef.hasfocued){
this.close();
}
}

我正在尝试使用选项卡导航弹出窗口。我想检查两个元素是否都没有焦点然后关闭弹出窗口。

【问题讨论】:

    标签: html angular typescript angular2-forms


    【解决方案1】:

    您可以使用focusblur 之类的事件

    <th-button id="btnPopClose" #btnPopClose type="button" class="btn btn-default" 
       (click)="onFavPopupClose()"
       (focus)="isBtnPopCloseFocused = true" 
       (blur)="isBtnPopCloseFocused = false">{{closeButtonText}}
    </th-button>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      相关资源
      最近更新 更多