2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2017-03-28 15:10:07 +08:00
|
|
|
|
2017-11-01 11:47:22 +08:00
|
|
|
export interface InputElementProps {
|
2019-06-24 11:29:58 +08:00
|
|
|
children: React.ReactElement<any>;
|
2017-11-01 11:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class InputElement extends React.Component<InputElementProps, any> {
|
2017-08-17 13:09:18 +08:00
|
|
|
saveRef = (ele: HTMLInputElement) => {
|
2017-11-01 11:47:22 +08:00
|
|
|
const { ref: childRef } = this.props.children as any;
|
2017-08-17 13:09:18 +08:00
|
|
|
if (typeof childRef === 'function') {
|
|
|
|
childRef(ele);
|
|
|
|
}
|
2018-12-07 16:17:45 +08:00
|
|
|
};
|
2019-03-26 14:47:50 +08:00
|
|
|
|
2017-03-28 15:10:07 +08:00
|
|
|
render() {
|
2018-12-07 16:17:45 +08:00
|
|
|
return React.cloneElement(
|
|
|
|
this.props.children,
|
|
|
|
{
|
|
|
|
...this.props,
|
|
|
|
ref: this.saveRef,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
);
|
2017-03-28 15:10:07 +08:00
|
|
|
}
|
|
|
|
}
|