Fix: Date typing improvements#2046
Open
joe-herbert wants to merge 5 commits into
Open
Conversation
|
Contributor
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes this issue regarding unexpected behaviour when typing into a date field.
This can be broken down into three fixes:
Firstly, pressing backspace when the year segment only had one character caused the entire date to be cleared, frustratingly meaning the user had to enter the day and month again. We now have a private
#segmentClearedValuevariable which is used to specify whether the segment was cleared by the user, in which case we should not clear the whole input. This method ensures if this code is triggered from anywhere else its behaviour is unchanged.Secondly, there was an issue regarding when to move to the next segment when backspace had been used. The existing implementation thinks you should move forward after typing enough characters to match the number of backspaces, however this causes an issue when someone makes a typo. e.g. if someone makes a mistake at the start of entering the year and they type
1,Backspace,2the focus will jump to the next segment before the user gets a chance to type the rest of the year. This fix now sticks with the same segment until that segment is completed.Thirdly, there were issues stemming from padding incomplete segments with preceding zeros. These zeros were then treated as part of the segment's value, which caused confusion when completing or editing a segment, particularly noticeable when backspacing in the year segment. This fix uses integer division to remove the last character and then reapplies the padding before it is shown. This ensures the full padding is always shown to the user but the preceding zeros don't impact the backspace process.
The
should handle backspacing the year segment appropriatelydate-field test has also been updated to reflect the new behaviour.This has been tested manually, and tests have been run to confirm the only failures were pre-existing.
If there are any changes you'd like, please let me know!