-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[TimePicker] Update time state on new defaultTime prop. #3095
Conversation
newState.muiTheme = nextContext.muiTheme; | ||
} | ||
if (!Date.isEqualTime(this.state.time, nextProps.defaultTime)) { | ||
newState.time = nextProps.defaultTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the defaultTime
should only be used during the first render, like for a regular <input />
. I would add a new value
property for your "controlled" use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari of course, that would be better, the prop value
is going to have precedence over defaultTime
at first rendering, right?
Ah, technically it has been waiting for revision since then. Happens frequently. I call them drive by PRs! :D Anyway, back to business! DatePicker has a |
The Tests have been added to prove the fix, although they don't cover all scenarios, it show at least that the change is working 😅 |
Gonna leave @oliviertassinari for the final review, but have to say, awesome work! |
@rscnt Wow, thanks for the tests! Could you update the examples of the doc? I would be better to remove the warnings from the console (linked to the deprecated methods) |
@@ -80,6 +82,11 @@ const TimePicker = React.createClass({ | |||
textFieldStyle: React.PropTypes.object, | |||
|
|||
/** | |||
* Sets the time for the Time Picker programmatically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing dot at the end of the sentence.
@oliviertassinari docs have been updated, commentaries have been applied and mistakes have been fixed 😄 |
super(props); | ||
this.state = {value24: new Date(), value12: new Date()}; | ||
this.handleChangeTimePicker24 = this.handleChangeTimePicker24.bind(this); | ||
this.handleChangeTimePicker12 = this.handleChangeTimePicker12.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for using bind over the arrow function property?
@oliviertassinari warnings added and TimePicker/ComplexExample is now using arrow syntax. |
@rscnt Thanks! I will have a closer look at this PR, but that look good so far. I have seen some minor issue, like using |
@oliviertassinari 'squashed' 👍 |
@@ -3,13 +3,17 @@ import TimePicker from 'material-ui/lib/time-picker/time-picker'; | |||
|
|||
export default class TimePickerExampleComplex extends React.Component { | |||
|
|||
constructor(props) { | |||
super(props); | |||
this.state = {value24: new Date(), value12: new Date()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have only one state for this example with a default value null as before.
It would be something like:
this.state = {
value: null,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@rscnt We are almost there :). |
1dcbd2f
to
e180bc3
Compare
Hah, I was using this PR to test error output on |
@@ -204,7 +228,7 @@ const TimePicker = React.createClass({ | |||
{...other} | |||
style={textFieldStyle} | |||
ref="input" | |||
value={time === emptyTime ? null : this.formatTime(time)} | |||
value={time === emptyTime ? null : DateTime.formatTime(time, this.props.format, this.props.pedantic)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about DateTime.formatTime(time, format, pedantic)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@rscnt Thanks! |
6c5798a
to
2b41865
Compare
@@ -165,4 +223,12 @@ export default { | |||
return ~~(this.monthDiff(d1, d2) / 12); | |||
}, | |||
|
|||
isEqualTime(d1, d2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for keeping this method? That's no longer used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@oliviertassinari removed. |
ref="picker24hr" | ||
format="24hr" | ||
hintText="24hr Format" | ||
<TimePicker format="ampm" hintText="12hr Format" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you follow this coding style?
<TimePicker
format="ampm"
hintText="12hr Format"
@rscnt Thanks! I have done a final review of this PR, aside from my two comments and the Travis fail. I think that we can merge. Good job 🎉.
|
This looks awesome 😍 can't wait to see it merged 👍 |
59f76b9
to
b6e0271
Compare
- TimePicker#getValue is now deprecated. - TimePicker#setValue is now deprecated. - Added value prop. - defaultTime is only used if value is not defined on props. - Added tests for TimePicker initialization behavior. - Adding utils/DateTime#formatTime Fixes mui#3094 Signed-off-by: rscnt <[email protected]>
@oliviertassinari sorry, linting issues have been fixed. |
[TimePicker] Update time state on new defaultTime prop.
@rscnt Thanks that's a great feature 🚀. |
This pull request try to fix #3094.
If a TimePicker instance is already mounted and a new defaultTime is passed to it, the time state value doesn't update.
There was already a pull request aiming to fix this and other issues for this component at #2027, but it has been waiting for review since Nov 24, 2015.