通过给ref添加focus来获取焦点
...
const elementRef = createRef();
// 在控制element组件的方法中,添加focus事件以添加焦点
const fatherFunction = () => {
...
elementRef.current.focus();
}
<Father>
<Child elementRef={elementRef} />
</Father>
...
--------------------
...
<Child>
<Element elementRef={this.props.elementRef}/>
</Child>
...
--------------------
...
// 把ref加在onBlur的同一层级
<Element>
<div
onBlur={...}
ref={this.props.elementRef}
>
onBlur失效的element
</div>
</Element>