findDOMNode to refs, close #12843

This commit is contained in:
afc163 2018-10-30 16:08:55 +08:00
parent de492b90a4
commit 087f7efd10

View File

@ -1,5 +1,4 @@
import * as React from 'react';
import { findDOMNode } from 'react-dom';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import Wave from '../_util/wave';
@ -89,6 +88,7 @@ export default class Button extends React.Component<ButtonProps, any> {
};
private delayTimeout: number;
private buttonNode: HTMLElement | null;
constructor(props: ButtonProps) {
super(props);
@ -127,10 +127,16 @@ export default class Button extends React.Component<ButtonProps, any> {
}
}
saveButtonRef = (node: HTMLElement | null) => {
this.buttonNode = node;
}
fixTwoCNChar() {
// Fix for HOC usage like <FormatMessage />
const node = (findDOMNode(this) as HTMLElement);
const buttonText = node.textContent || node.innerText;
if (!this.buttonNode) {
return;
}
const buttonText = this.buttonNode.textContent || this.buttonNode.innerText;
if (this.isNeedInserted() && isTwoCNChar(buttonText)) {
if (!this.state.hasTwoCNChar) {
this.setState({
@ -208,6 +214,7 @@ export default class Button extends React.Component<ButtonProps, any> {
className={classes}
onClick={this.handleClick}
title={title}
ref={this.saveButtonRef}
>
{iconNode}{kids}
</a>
@ -224,6 +231,7 @@ export default class Button extends React.Component<ButtonProps, any> {
className={classes}
onClick={this.handleClick}
title={title}
ref={this.saveButtonRef}
>
{iconNode}{kids}
</button>