Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dialog/Overlay Issue #304 #406

Merged
merged 2 commits into from
Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/app/components/pages/components/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var DatePickerPage = React.createClass({

<DatePicker
hintText="Landscape Dialog"
mode="landscape"/>
mode="landscape" />

</ComponentDoc>
);
Expand Down
14 changes: 5 additions & 9 deletions src/js/dialog-window.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var DialogWindow = React.createClass({

componentDidMount: function() {
this._positionDialog();
if (this.props.openImmediately) this.refs.dialogOverlay.preventScrolling();
},

componentDidUpdate: function (prevProps, prevState) {
Expand All @@ -63,7 +64,7 @@ var DialogWindow = React.createClass({
{this.props.children}
{actions}
</Paper>
<Overlay show={this.state.open} onTouchTap={this._handleOverlayTouchTap} />
<Overlay ref="dialogOverlay" show={this.state.open} autoLockScrolling={false} onTouchTap={this._handleOverlayTouchTap} />
</div>
);
},
Expand All @@ -73,21 +74,16 @@ var DialogWindow = React.createClass({
},

dismiss: function() {

CssEvent.onTransitionEnd(this.getDOMNode(), function() {
//allow scrolling
var body = document.getElementsByTagName('body')[0];
body.style.overflow = '';
});
this.refs.dialogOverlay.allowScrolling();
}.bind(this));

this.setState({ open: false });
if (this.props.onDismiss) this.props.onDismiss();
},

show: function() {
//prevent scrolling
var body = document.getElementsByTagName('body')[0];
body.style.overflow = 'hidden';
this.refs.dialogOverlay.preventScrolling();

this.setState({ open: true });
if (this.props.onShow) this.props.onShow();
Expand Down
31 changes: 30 additions & 1 deletion src/js/overlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ var Overlay = React.createClass({
mixins: [Classable],

propTypes: {
show: React.PropTypes.bool
show: React.PropTypes.bool,
autoLockScrolling: React.PropTypes.bool
},

getDefaultProps: function() {
return {
autoLockScrolling: true
};
},

componentDidUpdate: function(prevProps, prevState) {
if (this.props.autoLockScrolling) (this.props.show) ? this._preventScrolling() : this._allowScrolling();
},

render: function() {
Expand All @@ -22,6 +33,24 @@ var Overlay = React.createClass({
return (
<div {...other} className={classes} />
);
},

preventScrolling: function() {
if (!this.props.autoLockScrolling) this._preventScrolling();
},

allowScrolling: function() {
if (!this.props.autoLockScrolling) this._allowScrolling();
},

_preventScrolling: function() {
var body = document.getElementsByTagName('body')[0];
body.style.overflow = 'hidden';
},

_allowScrolling: function() {
var body = document.getElementsByTagName('body')[0];
body.style.overflow = '';
}

});
Expand Down