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

[date-picker] add prop open to toggle the dialog #457

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 9 additions & 3 deletions docs/src/app/components/pages/components/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var DatePickerPage = React.createClass({
'//Landscape Dialog\n' +
'<DatePicker\n' +
' hintText="Landscape Dialog"\n' +
' mode="landscape"/>';
' mode="landscape"/>';

var componentInfo = [
{
Expand All @@ -38,7 +38,13 @@ var DatePickerPage = React.createClass({
type: 'one of: portrait, landscape',
header: 'default: portrait',
desc: 'Tells the component to display the picker in portrait or landscape mode.'
}
},
{
name: 'open',
type: 'bool',
header: 'default: no used',
desc: 'Tells the component to show or dismiss the dialog.'
},
]
},
{
Expand Down Expand Up @@ -77,4 +83,4 @@ var DatePickerPage = React.createClass({

});

module.exports = DatePickerPage;
module.exports = DatePickerPage;
3 changes: 3 additions & 0 deletions src/js/date-picker/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var DatePicker = React.createClass({
defaultDate: React.PropTypes.object,
formatDate: React.PropTypes.func,
mode: React.PropTypes.oneOf(['portrait', 'landscape', 'inline']),
open: React.PropTypes.bool,
onFocus: React.PropTypes.func,
onTouchTap: React.PropTypes.func,
onChange: React.PropTypes.func,
Expand Down Expand Up @@ -46,6 +47,7 @@ var DatePicker = React.createClass({
onTouchTap,
onShow,
onDismiss,
open,
...other
} = this.props;
var classes = this.getClasses('mui-date-picker', {
Expand All @@ -69,6 +71,7 @@ var DatePicker = React.createClass({
<DatePickerDialog
ref="dialogWindow"
initialDate={this.state.dialogDate}
open={open}
onAccept={this._handleDialogAccept}
onShow={onShow}
onDismiss={onDismiss} />
Expand Down
25 changes: 20 additions & 5 deletions src/js/dialog-window.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var DialogWindow = React.createClass({
actions: React.PropTypes.array,
contentClassName: React.PropTypes.string,
openImmediately: React.PropTypes.bool,
open: React.PropTypes.bool,
onClickAway: React.PropTypes.func,
onDismiss: React.PropTypes.func,
onShow: React.PropTypes.func,
Expand All @@ -34,10 +35,24 @@ var DialogWindow = React.createClass({

getInitialState: function() {
return {
open: this.props.openImmediately || false
open: this.props.open || this.props.openImmediately || false
};
},

componentWillReceiveProps: function(nextProps) {
if(nextProps.hasOwnProperty('open')) {
this.setState({
open: nextProps.open,
});

if (nextProps.open) {
this.refs.dialogOverlay.preventScrolling();
} else {
this.refs.dialogOverlay.allowScrolling();
}
}
},

componentDidMount: function() {
this._positionDialog();
if (this.props.openImmediately) {
Expand All @@ -51,7 +66,7 @@ var DialogWindow = React.createClass({
},

render: function() {
var classes = this.getClasses('mui-dialog-window', {
var classes = this.getClasses('mui-dialog-window', {
'mui-is-shown': this.state.open
});
var contentClasses = 'mui-dialog-window-contents';
Expand Down Expand Up @@ -153,16 +168,16 @@ var DialogWindow = React.createClass({
//Vertically center the dialog window, but make sure it doesn't
//transition to that position.
if (this.props.repositionOnUpdate || !container.style.paddingTop) {
container.style.paddingTop =
container.style.paddingTop =
((containerHeight - dialogWindowHeight) / 2) - 64 + 'px';
}
}
},

_onShow: function() {
if (this.props.onShow) this.props.onShow();
},

_onDismiss: function() {
if (this.props.onDismiss) this.props.onDismiss();
},
Expand Down