Skip to content

Commit

Permalink
[fixed] selectable can properly be toggled on and off
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Sep 13, 2015
1 parent 92252e3 commit 386d4bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/BackgroundCells.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ class DisplayCells extends React.Component {
}

componentWillUnmount() {
this._selector && this._selector.teardown()
this._teardownSelectable();
}

componentWillReceiveProps(nextProps) {
if (nextProps.selectable && !this.props.selectable)
this._selectable();
if (!nextProps.selectable && this.props.selectable)
this._teardownSelectable();
}

render(){
Expand Down Expand Up @@ -104,6 +111,12 @@ class DisplayCells extends React.Component {
})
}

_teardownSelectable() {
if (!this._selector) return
this._selector.teardown();
this._selector = null;
}

_selectSlot({ endIdx, startIdx }) {
this.props.onSelectSlot &&
this.props.onSelectSlot({
Expand Down
18 changes: 16 additions & 2 deletions src/DaySlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ let DaySlot = React.createClass({
return { selecting: false };
},


componentDidMount() {
this.props.selectable
&& this._selectable()
},

componentWillUnmount() {
this._selector && this._selector.teardown()
this._teardownSelectable();
},

componentWillReceiveProps(nextProps) {
if (nextProps.selectable && !this.props.selectable)
this._selectable();
if (!nextProps.selectable && this.props.selectable)
this._teardownSelectable();
},

render() {
Expand Down Expand Up @@ -214,7 +222,13 @@ let DaySlot = React.createClass({
})
},

_selectSlot({ startDate, endDate, endSlot, startSlot }){
_teardownSelectable() {
if (!this._selector) return
this._selector.teardown();
this._selector = null;
},

_selectSlot({ startDate, endDate, endSlot, startSlot }) {
let current = startDate
, slots = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Month.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ let MonthView = React.createClass({

return (
<BackgroundCells
selectable
selectable={this.props.selectable}
slots={7}
ref={r => this._bgRows[idx] = r}
onSelectSlot={onSelectSlot}
Expand Down

0 comments on commit 386d4bc

Please sign in to comment.