Skip to content

Commit

Permalink
Replace findDOMNode by ref callback (balloob#98)
Browse files Browse the repository at this point in the history
* Remove findDOMNode

* fix linters

* Simplify sidebar ref

* Back to sidebar ref callback

* Fix class property error

* Fix eslint error
  • Loading branch information
BDav24 authored and balloob committed Feb 15, 2017
1 parent 5c40de6 commit 17eafd6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import ReactDOM from 'react-dom';

const CANCEL_DISTANCE_ON_SCROLL = 20;

Expand Down Expand Up @@ -75,6 +74,7 @@ class Sidebar extends React.Component {
this.onTouchMove = this.onTouchMove.bind(this);
this.onTouchEnd = this.onTouchEnd.bind(this);
this.onScroll = this.onScroll.bind(this);
this.saveSidebarRef = this.saveSidebarRef.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -180,13 +180,17 @@ class Sidebar extends React.Component {
}

saveSidebarWidth() {
const width = ReactDOM.findDOMNode(this.refs.sidebar).offsetWidth;
const width = this.sidebar.offsetWidth;

if (width !== this.state.sidebarWidth) {
this.setState({sidebarWidth: width});
}
}

saveSidebarRef(node) {
this.sidebar = node;
}

// calculate the sidebarWidth based on current touch info
touchSidebarWidth() {
// if the sidebar is open and start point of drag is inside the sidebar
Expand Down Expand Up @@ -312,7 +316,7 @@ class Sidebar extends React.Component {

return (
<div {...rootProps}>
<div className={this.props.sidebarClassName} style={sidebarStyle} ref="sidebar">
<div className={this.props.sidebarClassName} style={sidebarStyle} ref={this.saveSidebarRef}>
{this.props.sidebar}
</div>
<div className={this.props.overlayClassName}
Expand Down

0 comments on commit 17eafd6

Please sign in to comment.