mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
27 lines
711 B
TypeScript
27 lines
711 B
TypeScript
import React from 'react';
|
|
import { findDOMNode } from 'react-dom';
|
|
|
|
export default class InputElement extends React.Component<any, any> {
|
|
private ele: HTMLInputElement;
|
|
|
|
focus = () => {
|
|
this.ele.focus ? this.ele.focus() : (findDOMNode(this.ele) as HTMLInputElement).focus();
|
|
}
|
|
blur = () => {
|
|
this.ele.blur ? this.ele.blur() : (findDOMNode(this.ele) as HTMLInputElement).blur();
|
|
}
|
|
saveRef = (ele: HTMLInputElement) => {
|
|
this.ele = ele;
|
|
const childRef = this.props.children.ref;
|
|
if (typeof childRef === 'function') {
|
|
childRef(ele);
|
|
}
|
|
}
|
|
render() {
|
|
return React.cloneElement(this.props.children, {
|
|
...this.props,
|
|
ref: this.saveRef,
|
|
}, null);
|
|
}
|
|
}
|