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

Fix NumberInput should support entering a decimal number with a transitory invalid value #8610

Merged
merged 1 commit into from Jan 31, 2023

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Jan 30, 2023

Fix #8593

'resources.posts.fields.views'
) as HTMLInputElement;
fireEvent.focus(input);
await userEvent.type(input, '0.01', { delay: 100 });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason I could not replicate this test using a comma ('0,01') because it fails.
But I have tested manually and it works fine with a comma, both on Desktop and Mobile.
Could be an issue with the locale in Jest being different from the locale of my computer.

Copy link
Member

Choose a reason for hiding this comment

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

indeed

}
hasFocus.current = false;
const stringValue = format(field.value);
setValue(value => (value !== stringValue ? stringValue : value));
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you need to do that. onChange already sets the value, doesn't it?

Copy link
Member

Choose a reason for hiding this comment

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

OK, understood: the use case is: a user enters "0.0" and blurs. The form value is "0", but the displayed value is different - and this is misleading. Updating the displayed value based on the form value helps the user know what's going to be submitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly 🙂

'resources.posts.fields.views'
) as HTMLInputElement;
fireEvent.focus(input);
await userEvent.type(input, '0.01', { delay: 100 });
Copy link
Member

Choose a reason for hiding this comment

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

indeed

@fzaninotto fzaninotto merged commit bb039d6 into master Jan 31, 2023
@fzaninotto fzaninotto deleted the fix-numberinput-decimals-mobile branch January 31, 2023 08:56
@fzaninotto fzaninotto added this to the 4.7.3 milestone Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to apply under decimal started by 0 with <NumberInput /> on mobile devices
2 participants