![](/img/trans.png)
[英]Angular 2(4) component with ControlValueAccessor testing
[英]Strange focus behavoir in Safari with Angular custom component (ControlValueAccessor)
我使用 ControlValueAccessor 制作了一个自定义 Angular (8.x) 组件。 使用两个或多个组件时,我在 Safari(桌面和移动)中出现奇怪的行为。 当我单击第二个输入元素时,焦点跳回到第一个。 我究竟做错了什么?
请参阅https://stackblitz.com/edit/angular-qcgefd 。
在 Chrome 和 Firefox(桌面和移动)中一切正常
在文件 fieldform.component.html 中,您定义了一个 ID 和名称,其值为“用户名”。 如果您随后在一个表单中多次使用该组件。 每个字段都具有相同的名称和 ID。 显然 Safari 不喜欢这样。 要解决这个问题,您必须从 fieldform.component 中删除名称和 ID。
fieldform.component.html 的新代码。
<div class="RPnbM">
<label class="dozyoM">
<input [type]="type" class="fhJDUk" (focusin)="onFocusIn()" (focusout)="onFocusOut()" [(ngModel)]="value"/>
<span class="gUpyls" [class.kPeLXy]="hasValue() && !hasFocus" [class.hisroG]="hasFocus" >{{label}}</span>
</label>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.