Skip to content

Commit

Permalink
Merge pull request mui#1939 from tyfoo/feature/TimePicker-openDialog
Browse files Browse the repository at this point in the history
[TimePicker] openDialog() method similar to DatePicker
  • Loading branch information
oliviertassinari committed Oct 22, 2015
2 parents bba2703 + 77f71aa commit 2c2df5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docs/src/app/components/pages/components/time-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ let TimePickerPage = React.createClass({
header: 'TimePicker.formatTime(time)',
desc: 'Formats the Date object to a current component\'s time format.',
},
{
name: 'openDialog',
header: 'TimePicker.openDialog()',
desc: 'Opens the time-picker dialog programmatically. Use this if you want to open the ' +
'dialog in response to some event other than focus/tap on the input field, such as an ' +
'external button click.',
},
{
name: 'focus',
header: 'TimePicker.focus()',
desc: 'An alias for the `openDialog()` method to allow more generic use alongside `TextField`.',
},
],
},
{
Expand Down
20 changes: 16 additions & 4 deletions src/time-picker/time-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ const TimePicker = React.createClass({
this.refs.input.setValue(this.formatTime(t));
},

/**
* Alias for `openDialog()` for an api consistent with TextField.
*/
focus() {
this.openDialog();
},

openDialog() {
this.setState({
dialogTime: this.getTime(),
});

this.refs.dialogWindow.show();
},

_handleDialogAccept(t) {
this.setTime(t);
if (this.props.onChange) this.props.onChange(null, t);
Expand All @@ -133,11 +148,8 @@ const TimePicker = React.createClass({
_handleInputTouchTap(e) {
e.preventDefault();

this.setState({
dialogTime: this.getTime(),
});
this.openDialog();

this.refs.dialogWindow.show();
if (this.props.onTouchTap) this.props.onTouchTap(e);
},
});
Expand Down

0 comments on commit 2c2df5d

Please sign in to comment.