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

Components: Fix the timepicker, only update the values on blur #4193

Merged
merged 1 commit into from
Jan 5, 2018

Conversation

youknowriad
Copy link
Contributor

closes #3661

This PR changes the behavior of the TimPicker to be able to edit it freely and do the validation and updates on blur only.

This also makes the Component API more consistent, the format of the input and output value is made consistent. (Moment is only internal while the API expects timezone-less dates)

Testing instructions

  • Check that you can type anything in the time field and it resets on blur
  • Check that you can clear the input and type an hour

@youknowriad youknowriad added the General Interface Parts of the UI which don't fall neatly under other labels. label Dec 28, 2017
@youknowriad youknowriad self-assigned this Dec 28, 2017
const { onChange } = this.props;
const { am, date, hours } = this.state;
if ( am === value ) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ever fire, or is it just for sanity here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does fire when you hit the "toggled" button

Copy link
Contributor

@chriskmnds chriskmnds Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool, thanks for clarifying. It wasn't clear to me, and it's not covered by the tests either, so I thought to ask :-)

/**
* Module Constants
*/
const TIMEZONELESS_FORMAT = 'YYYY-MM-DDTHH:mm:ss';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just TIME_FORMAT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input and the output format should be the same, that's the format we have in the post object. We could use only a time format for time and date format for date but this means adding some "unnecessary" date manipulations in the parent component date-time (extract time and date on input, and recompute the whole date on change). I think it's just for convenience.

isToggled={ am === 'AM' }
onClick={ this.updateAmPm( 'AM' ) }
>
{ __( 'AM' ) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these need some translation context in general. cc @yoavf

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if these need some translation context in general.

I would have possibly expected context to be good here, but noting elsewhere in core it is not provided:

https://github.com/WordPress/wordpress-develop/blob/f3d3254/src/wp-includes/class-wp-locale.php#L197-L201

@youknowriad
Copy link
Contributor Author

Going to merge this if no more concerns?

@mtias
Copy link
Member

mtias commented Jan 5, 2018

🚢

@youknowriad youknowriad merged commit 74e95a9 into master Jan 5, 2018
@youknowriad youknowriad deleted the fix/time-picker branch January 5, 2018 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Interface Parts of the UI which don't fall neatly under other labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entering a time in the post publish settings is not working
4 participants