Skip to content

Commit

Permalink
Position dialog onMount and onUpdate. Fixes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Nguyen committed Nov 30, 2014
1 parent 3c0556a commit a21ae38
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/js/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var Dialog = React.createClass({
};
},

componentDidUpdate: function (prevProps, prevState) {
//calculate height and use that to center the dialog vertically
var dom = this.getDOMNode(),
height = dom.offsetHeight;
componentDidMount: function() {
this._positionDialog();
},

dom.style.marginTop = -1 * height / 2 + 'px';
componentDidUpdate: function (prevProps, prevState) {
this._positionDialog();
},

render: function() {
Expand Down Expand Up @@ -78,6 +78,14 @@ var Dialog = React.createClass({
if (this.props.onShow) this.props.onShow();
},

_positionDialog: function() {
//calculate height and use that to center the dialog vertically
var el = this.getDOMNode(),
height = el.offsetHeight;

el.style.marginTop = -1 * height / 2 + 'px';
},

_handleClickAway: function() {
this.dismiss();
},
Expand Down

0 comments on commit a21ae38

Please sign in to comment.