【发布时间】:2020-07-02 18:20:12
【问题描述】:
我在 react 中使用 refs。我注意到 .focus() 方法在 chrome 和 firefox 中并不一致。
在这个沙箱https://codesandbox.io/s/a-guide-to-react-refs-2nd-example-vl9sj?file=/src/Ref.js
我创建了很多输入字段,第一个输入字段中有 ref。当用户单击提交按钮时,我在输入参考上调用 .focus() 方法。
如下图所示。
左图->火狐
右像素-> Chrome
正如您所见,chrome 在聚焦时会在其上方添加一定的空间,而 Firefox 则不会。这与 IE 中显示的行为相同。
有什么方法可以让他们两者的行为保持一致。或者除了焦点之外我还能做些什么来获得焦点行为?
在 IE 中编辑:
.focus {
outline: #015ecc solid 2px;
outline-offset: -2px; // You don't always need to provide offset. But in some scenarios you might need to provide outline offset as it's not default offset property.
::-ms-focus-inner { //FF adds some inner border to the elements, this will remove it.
border: 0;
}
}
【问题讨论】:
标签: javascript reactjs