One of the most important thing when building custom form component is adding accessbility support.

The component should be focusable. we can achieve this by adding 'tabindex="0"':

      <div
tabindex="0"
>

Add some css class for foucs:

      <div
[class.focus]="focused"
tabindex="0"
(focus)="onFocus($event)"
(blur)="onBlur($event)"
>
.stock-counter {
& .focus {
box-shadow: 0 1px 1px rgba(0, 0, 0, .6);
} ...
}
  onFocus() {
this.focused = true;
this.onTouch();
} onBlur() {
this.focused = false;
this.onTouch();
}

Handle keydwon event with code:

      <div
[class.focus]="focused"
tabindex="0"
(keydown)="onKeyDown($event)"
(focus)="onFocus($event)"
(blur)="onBlur($event)"
>
  onKeyDown(event: KeyboardEvent) {

    const handler = {
ArrowDown: () => this.decrement(),
ArrowUp: () => this.increment()
}; if(handler[event.code]) {
event.preventDefault();
event.stopPropagation();
handler[event.code]();
}
}

[Angular] Adding keyboard events to our control value accessor component的更多相关文章

  1. jQuery.Hotkeys - lets you watch for keyboard events anywhere in your code supporting almost any key combination

    About jQuery Hotkeys is a plug-in that lets you easily add and remove handlers for keyboard events a ...

  2. [Angular] Implement a custom form component by using control value accessor

    We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...

  3. [Angular] Angular Global Keyboard Handling With EventManager

    If we want to add global event handler, we can use 'EventManager' from '@angular/platform-broswer'. ...

  4. [Angular] Router outlet events

    For example, we have a component which just simply render router-outlet: import { Component } from ' ...

  5. [Angular 2] Using events and refs

    This lesson shows you how set listen for click events using the (click) syntax. It also covers getti ...

  6. [AngularFire] Angular File Uploads to Firebase Storage with Angular control value accessor

    The upload class will be used in the service layer. Notice it has a constructor for file attribute, ...

  7. [Angular] Progress HTTP Events with 'HttpRequest'

    New use case that is supported by the HTTP client is Progress events. To receive these events, we cr ...

  8. [Angular2 Form] Create custom form component using Control Value Accessor

    //switch-control component import { Component } from '@angular/core'; import { ControlValueAccessor, ...

  9. Javascript Madness: Mouse Events

    http://unixpapa.com/js/mouse.html Javascript Madness: Mouse Events Jan WolterAug 12, 2011 Note: I ha ...

随机推荐

  1. qt多线程

    为什么要用多线程? 传统的图形用户界面应用程序都只有一个执行线程,并且一次只执行一个操作.如果用户从用户界面中调用一个比较耗时的操作,当该操作正在执行时,用户界面通常会冻结而不再响应.这个问题可以用事 ...

  2. Linux文本编辑器

    1.编辑模式 2.命令模式 3.底部命令模式 注意:如果发现编辑不了.可能是因为非法退出产生一个后缀名为.swp 的临时隐藏文件. 将其删除重新编辑即可!

  3. leaf cell

    leaf cell是否可以理解为设计中与或非门等这些基本的单元?

  4. 四、Docker+Tomcat

    原文:四.Docker+Tomcat 一.下载Tomcat镜像 具体可以search 搜索tomcat 相关镜像 docker pull sonodar/jdk8-tomcat8 二.创建容器 doc ...

  5. [置顶] MVC三层架构在各框架中的特征

    1.从结构上分析jsp+servlet图解原理: 在基于mvc设计模式下的最原始的jsp+Servlet框架,在某种程度上是不能够达到mvc最直观的体现.当客户端发送请求到服务器时,服务器会将从客户端 ...

  6. hdu-3642--Get The Treasury-线段树求面积并

    求空间中叠加3次及3次以上的体积. 由于|z|<=500.所以直接把z轴剥离出来1000层. 然后对于每一层进行线段树求面积并. #include<stdio.h> #include ...

  7. 报错 关于python的x和y不等长

    ValueError: shape mismatch: objects cannot be broadcast to a single shape 这个错误可能是因为传入的两个参数数据长度不一样,比如 ...

  8. PatentTips - Method, apparatus and system for instructing a virtual device from a virtual machine

    BACKGROUND OF THE INVENTION A virtual machine (VM) may be or include a framework or environment crea ...

  9. ArcGIS在线帮助的使用指南

    一直感觉ArcGIS的在线帮助就是鸡肋,没想到网络常见的所谓的高大上的博文,也不过是对GIS 在线帮助的拷贝,或者简单修改而已.其实ArcGIS的在线帮助包含了以下几个很好用的模块: 备注 ArcGI ...

  10. LA 3989 - Ladies' Choice 稳定婚姻问题

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...