-
Notifications
You must be signed in to change notification settings - Fork 908
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
Filter out leading zeros in How-To Block time input fields #10705
Filter out leading zeros in How-To Block time input fields #10705
Conversation
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.
CR done 🏗
onChange={ ( event ) => setAttributes( { hours: Math.max( 0, event.target.value ) } ) } | ||
id="hours-input" | ||
onChange={ ( event ) => { | ||
const newValue = event.target.value.replace( /^[0]+/, "" ); |
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'd vouch for replacing this with a function that strips off leading zeros and allows (optional) parameters to be passed for the min/max values. If the value results into a fully empty string, return null
.
Psuedo-implementation:
function formatDuration( duration, maxDuration = null ) {
const newDuration = duration.replace( /^[0]+/, "" );
if ( newDuration === "" ) {
return null;
}
if ( maxDuration !== null ) {
return Math.min( Math.max( 0, newDuration ), maxDuration );
}
return Math.max( 0, newDuration );
}
I believe this will also solve the issue that you cannot clear either field without it automatically adding a zero.
…ck-should-not-allow-leading-zeroes
To fix the displaying of the time needed
…tps://github.com/Yoast/wordpress-seo into 10663-HowToBlock-should-not-allow-leading-zeroes # Conflicts: # js/src/structured-data-blocks/how-to/components/HowTo.js
…uld-not-allow-leading-zeroes
I think there's an usability and accessibility issue with this. By using the placeholder attributes, we are asking users to enter hours and minutes in a specific format. The two fields clearly suggest Now, what if, as a user, I want to enter a duration of 1 hour? I'll diligently try to follow the instructions and enter I'd suggest to consider to allow a double zero I'd argue that also the hour field placeholder is asking for a value with 2 digits, so what we're communicating to users is to enter On a side note:
I haven't closely followed the development but, unless I'm missing something, at least the minutes |
@afercia when the user enters 0 in both, the time duration is not shown in the frontend, so that is not an issue. |
CR 👍 |
Acceptance done, but please fix the merge conflict first. |
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Test instructions
This PR can be tested by following these steps:
When you set minutes to 59 in your post it will say "one hour", this is the doing of humanize() and will be fixed in a separate issue.0
in any of the fields is fine and that should not be removed.Quality assurance
Fixes #10663
Fixes #10668