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(number-field): allow only numeric characters for Japanese/Chinese IME #4817

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Rocss
Copy link
Contributor

@Rocss Rocss commented Oct 14, 2024

Description

Text candidates appear for characters by inputting them with Japanese/Simplified Chinese/Traditional Chinese IME for numbers in respective fields where only digits are allowed.

Related issue(s)

Motivation and context

I think users should not be allowed to type "love" for example in an sp-number-field, when using Japanese/Chinese IME.
We do this check for english keyboard, but it seems it was missed to internationalised keyboards.
Internal tracking: CCEX-145560

How has this been tested?

  • Test case 1 Repeat for Safari/Chrome/Firefox

    1. Go here
    2. Make sure to use Japanese IME (you can find this in the Keyboard settings)
    3. Try to enter some text (ex. 'あい'in JP) into the numeric input box.
    4. You should not be allowed to enter characters that are not numeric
  • Did it pass in Desktop?

  • Did it pass in Mobile?

  • Did it pass in iPad?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

Copy link

Branch preview

Visual regression test results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Copy link

github-actions bot commented Oct 14, 2024

Lighthouse scores

Category Latest (report) Main (report) Branch (report)
Performance 0.99 0.99 0.99
Accessibility 1 1 1
Best Practices 1 1 1
SEO 1 0.92 0.92
PWA 1 1 1
What is this?

Lighthouse scores comparing the documentation site built from the PR ("Branch") to that of the production documentation site ("Latest") and the build currently on main ("Main"). Higher scores are better, but note that the SEO scores on Netlify URLs are artifically constrained to 0.92.

Transfer Size

Category Latest Main Branch
Total 228.822 kB 217.158 kB 217.056 kB 🏆
Scripts 58.11 kB 52.537 kB 🏆 52.552 kB
Stylesheet 34.529 kB 30.213 kB 30.088 kB 🏆
Document 6.221 kB 5.463 kB 5.463 kB
Font 126.985 kB 126.596 kB 🏆 126.605 kB

Request Count

Category Latest Main Branch
Total 52 52 52
Scripts 41 41 41
Stylesheet 5 5 5
Document 1 1 1
Font 2 2 2

@coveralls
Copy link
Collaborator

coveralls commented Oct 14, 2024

Pull Request Test Coverage Report for Build 11386739960

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 16 of 17 (94.12%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 98.228%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/number-field/src/NumberField.ts 16 17 94.12%
Totals Coverage Status
Change from base Build 11324234816: -0.002%
Covered Lines: 32958
Relevant Lines: 33371

💛 - Coveralls

Copy link

github-actions bot commented Oct 14, 2024

Tachometer results

Chrome

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 541 kB 73.02ms - 74.44ms - faster ✔
8% - 11%
6.77ms - 8.74ms
branch 517 kB 80.81ms - 82.16ms slower ❌
9% - 12%
6.77ms - 8.74ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 496 kB 77.13ms - 81.91ms - faster ✔
2% - 10%
1.58ms - 8.57ms
branch 472 kB 82.05ms - 87.15ms slower ❌
2% - 11%
1.58ms - 8.57ms
-
Firefox

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 541 kB 151.83ms - 157.49ms - faster ✔
8% - 13%
12.79ms - 21.93ms
branch 517 kB 168.43ms - 175.61ms slower ❌
8% - 14%
12.79ms - 21.93ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 496 kB 159.63ms - 166.17ms - faster ✔
0% - 5%
0.30ms - 9.14ms
branch 472 kB 164.65ms - 170.59ms slower ❌
0% - 6%
0.30ms - 9.14ms
-

@Rocss Rocss marked this pull request as ready for review October 15, 2024 07:23
@Rocss Rocss requested a review from a team as a code owner October 15, 2024 07:23
@@ -496,6 +496,18 @@ export class NumberField extends TextfieldBase {

protected override handleInput(event: InputEvent): void {
if (this.isComposing) {
// If user actually types a new character.
if (event.data) {
Copy link
Contributor

@Rajdeepc Rajdeepc Oct 16, 2024

Choose a reason for hiding this comment

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

If event.data is null, it could lead to unexpected behavior. For example, pressing backspace or delete can cause event.data to be empty.An early return would be more tactical!

if (event.data === null || event.data === '') {
    return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (event.data) also guards for null and empty string, and after this this block is a return at line 511.
Wouldn't it work the same?

// Don't allow non-numeric characters even in composing mode.
const partialValue = this.convertValueToNumber(event.data);

if (Number.isNaN(partialValue)) {
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 allow pasting inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

if (Number.isNaN(partialValue)) {
this.inputElement.value = this.indeterminate
? indeterminatePlaceholder
: this._trackingValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Resetting the value to this._trackingValue can be confusing! Can we show some validation feedback instead of a reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the same logic as on english keyboard (line 547), we are resetting here because you should not be able to type non-numeric numbers, so we're removing what you typed.

Copy link
Collaborator

@blunteshwar blunteshwar Oct 17, 2024

Choose a reason for hiding this comment

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

Makes Sense!
But in the storybook when the number-field has an initial value ='100', and user removes one zero with a backspace such that new value is now '10'. And now if user tries to type some non-numeric character in japanese, the values resets to '100' which should not happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed 👍 can you try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants