Browse Source

findDOMNode to refs, close #12843

pull/12887/head
afc163 6 years ago
parent
commit
087f7efd10
  1. 14
      components/button/button.tsx

14
components/button/button.tsx

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

Loading…
Cancel
Save