Skip to content

Commit 63eec19

Browse files
committed
Merge pull request #390 from thechriswalker/fix/floating-button-state-change
Fixes zdepth on change of "disabled" prop in FAB
2 parents bb80245 + f3d6937 commit 63eec19

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/js/floating-action-button.jsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ var EnhancedButton = require('./enhanced-button');
44
var FontIcon = require('./font-icon');
55
var Paper = require('./paper');
66

7+
var getZDepth = function(disabled) {
8+
var zDepth = disabled ? 0 : 2;
9+
return {
10+
zDepth: zDepth,
11+
initialZDepth: zDepth
12+
};
13+
};
14+
15+
716
var RaisedButton = React.createClass({
817

918
mixins: [Classable],
@@ -20,12 +29,14 @@ var RaisedButton = React.createClass({
2029
secondary: React.PropTypes.bool
2130
},
2231

23-
getInitialState: function() {
24-
var zDepth = this.props.disabled ? 0 : 2;
25-
return {
26-
zDepth: zDepth,
27-
initialZDepth: zDepth
28-
};
32+
componentWillMount: function() {
33+
this.setState(getZDepth(this.props.disabled));
34+
},
35+
36+
componentWillReceiveProps: function(newProps) {
37+
if(newProps.disabled !== this.props.disabled){
38+
this.setState(getZDepth(newProps.disabled));
39+
}
2940
},
3041

3142
componentDidMount: function() {
@@ -63,7 +74,7 @@ var RaisedButton = React.createClass({
6374
circle={true}>
6475

6576
<EnhancedButton {...other}
66-
className="mui-floating-action-button-container"
77+
className="mui-floating-action-button-container"
6778
onMouseDown={this._handleMouseDown}
6879
onMouseUp={this._handleMouseUp}
6980
onMouseOut={this._handleMouseOut}
@@ -74,7 +85,7 @@ var RaisedButton = React.createClass({
7485
{this.props.children}
7586

7687
</EnhancedButton>
77-
88+
7889
</Paper>
7990
);
8091
},

0 commit comments

Comments
 (0)