Skip to content

Commit 0c43167

Browse files
committed
Change this.isMounted to use componentDidMount and componentWillUnmount due to deprecation in es6
1 parent cc9bca7 commit 0c43167

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

components/SLDSTooltip/index.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class SLDSTooltip extends React.Component {
3939
};
4040
}
4141

42+
componentDidMount() {
43+
this.setState({ isMounted: true });
44+
}
45+
46+
componentWillUnmount() {
47+
this.setState({ isMounted: false });
48+
}
49+
4250
handleMouseClick() {
4351
this.setState({
4452
isOpen: !this.state.isOpen,
@@ -55,9 +63,10 @@ class SLDSTooltip extends React.Component {
5563
}
5664

5765
handleMouseLeave() {
58-
this.setState({isClosing: true});
66+
this.setState({ isClosing: true });
67+
5968
setTimeout(()=>{
60-
if(this.isMounted && this.state.isClosing){
69+
if(this.state.isMounted && this.state.isClosing){
6170
this.setState({
6271
isOpen: false,
6372
isClosing: false
@@ -119,7 +128,7 @@ class SLDSTooltip extends React.Component {
119128
horizontalAlign={this.getHorizontalAlign()}
120129
verticalAlign={this.getVerticalAlign()}
121130
flippable={false}
122-
onClose={this.handleCancel}>
131+
onClose={this.handleCancel.bind(this)}>
123132
<div className={cx(style)} role="tooltip">
124133
{this.getTooltipContent()}
125134
</div>
@@ -128,7 +137,7 @@ class SLDSTooltip extends React.Component {
128137

129138
render(){
130139
return (
131-
<span refs='tooltipTarget' onClick={this.props.openOn === 'click' ? this.handleMouseClick:null} onMouseEnter={this.props.openOn === 'hover' ? this.handleMouseEnter.bind(this):null} onMouseLeave={this.props.openOn === 'hover' ? this.handleMouseLeave.bind(this):null}>
140+
<span refs='tooltipTarget' onClick={this.props.openOn === 'click' ? this.handleMouseClick.bind(this):null} onMouseEnter={this.props.openOn === 'hover' ? this.handleMouseEnter.bind(this):null} onMouseLeave={this.props.openOn === 'hover' ? this.handleMouseLeave.bind(this):null}>
132141
{ this.props.children }
133142
{ this.getTooltip() }
134143
</span>

0 commit comments

Comments
 (0)