From 087f7efd10fead54b6112a03330861e0d24b27e4 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 30 Oct 2018 16:08:55 +0800 Subject: [PATCH] findDOMNode to refs, close #12843 --- components/button/button.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index b0e1cd89ce..cbd2a9e71c 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -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 { }; private delayTimeout: number; + private buttonNode: HTMLElement | null; constructor(props: ButtonProps) { super(props); @@ -127,10 +127,16 @@ export default class Button extends React.Component { } } + saveButtonRef = (node: HTMLElement | null) => { + this.buttonNode = node; + } + fixTwoCNChar() { // Fix for HOC usage like - 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 { className={classes} onClick={this.handleClick} title={title} + ref={this.saveButtonRef} > {iconNode}{kids} @@ -224,6 +231,7 @@ export default class Button extends React.Component { className={classes} onClick={this.handleClick} title={title} + ref={this.saveButtonRef} > {iconNode}{kids}