Skip to content

Commit

Permalink
Merge pull request mui#1940 from tyfoo/feature/TimePick-autoOk
Browse files Browse the repository at this point in the history
[TimePicker] autoOk prop to automatically close the dialog
  • Loading branch information
oliviertassinari committed Oct 23, 2015
2 parents c7f6a82 + bd0eb61 commit a18f08b
Show file tree
Hide file tree
Showing 5 changed files with 42 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 @@ -13,6 +13,12 @@ let TimePickerPage = React.createClass({
{
name: 'Props',
infoArray: [
{
name: 'autoOk',
type: 'boolean',
header: 'default: false',
desc: 'If true, automatically accept and close the picker on set minutes.',
},
{
name: 'defaultTime',
type: 'date object',
Expand Down Expand Up @@ -125,6 +131,12 @@ let TimePickerPage = React.createClass({
format="24hr"
hintText="24hr Format"
onChange={this._changeTimePicker12} />

<TimePicker
ref="pickerAutoOk"
format="24hr"
hintText="AutoOk"
autoOk={true} />
</CodeExample>
</ComponentDoc>
);
Expand Down
5 changes: 5 additions & 0 deletions docs/src/app/components/raw-code/time-picker-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
<TimePicker
format="24hr"
hintText="24hr Format" />

//Auto OK
<TimePicker
hintText="AutoOk"
autoOk={true} />
14 changes: 13 additions & 1 deletion src/time-picker/clock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const Clock = React.createClass({
mixins: [StylePropable],

propTypes: {
onChangeMinutes: React.PropTypes.func,
onChangeHours: React.PropTypes.func,
initialTime: React.PropTypes.object,
mode: React.PropTypes.oneOf(['hour', 'minute']),
format: React.PropTypes.oneOf(['ampm', '24hr']),
Expand Down Expand Up @@ -152,12 +154,17 @@ const Clock = React.createClass({
this.setState({
selectedTime: time,
});


const { onChangeHours } = this.props;

if (finished) {
setTimeout(() => {
this.setState({
mode: 'minute',
});
if (typeof(onChangeHours) === 'function') {
onChangeHours(time);
}
}, 100);
}
},
Expand All @@ -168,6 +175,11 @@ const Clock = React.createClass({
this.setState({
selectedTime: time,
});

const { onChangeMinutes } = this.props;
if (typeof(onChangeMinutes) === 'function') {
setTimeout(() => { onChangeMinutes(time); }, 0);
}
},

getSelectedTime() {
Expand Down
9 changes: 7 additions & 2 deletions src/time-picker/time-picker-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const TimePickerDialog = React.createClass({
},

propTypes: {
autoOk: React.PropTypes.bool,
initialTime: React.PropTypes.object,
onAccept: React.PropTypes.func,
onShow: React.PropTypes.func,
Expand Down Expand Up @@ -61,6 +62,7 @@ const TimePickerDialog = React.createClass({
initialTime,
onAccept,
format,
autoOk,
...other,
} = this.props;

Expand Down Expand Up @@ -89,7 +91,9 @@ const TimePickerDialog = React.createClass({
secondary={true}
onTouchTap={this._handleOKTouchTap} />,
];


const onClockChangeMinutes = (autoOk === true ? this._handleOKTouchTap : undefined);

return (
<Dialog {...other}
ref="dialogWindow"
Expand All @@ -103,7 +107,8 @@ const TimePickerDialog = React.createClass({
<Clock
ref="clock"
format={format}
initialTime={initialTime} />
initialTime={initialTime}
onChangeMinutes={onClockChangeMinutes} />
</Dialog>
);
},
Expand Down
6 changes: 5 additions & 1 deletion src/time-picker/time-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TimePicker = React.createClass({
mixins: [StylePropable, WindowListenable],

propTypes: {
autoOk: React.PropTypes.bool,
defaultTime: React.PropTypes.object,
format: React.PropTypes.oneOf(['ampm', '24hr']),
pedantic: React.PropTypes.bool,
Expand All @@ -34,6 +35,7 @@ const TimePicker = React.createClass({
defaultTime: null,
format: 'ampm',
pedantic: false,
autoOk: false,
};
},

Expand Down Expand Up @@ -76,6 +78,7 @@ const TimePicker = React.createClass({

render() {
let {
autoOk,
format,
onFocus,
onTouchTap,
Expand Down Expand Up @@ -104,7 +107,8 @@ const TimePicker = React.createClass({
onAccept={this._handleDialogAccept}
onShow={onShow}
onDismiss={onDismiss}
format={format} />
format={format}
autoOk={autoOk} />
</div>
);
},
Expand Down

0 comments on commit a18f08b

Please sign in to comment.