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

Merged
merged 9 commits into from
Nov 7, 2024

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

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 251.604 kB 236.514 kB 🏆 236.878 kB
Scripts 61.345 kB 54.224 kB 🏆 54.31 kB
Stylesheet 54.071 kB 47.788 kB 🏆 48.10 kB
Document 6.192 kB 5.433 kB 🏆 5.487 kB
Font 127.015 kB 126.658 kB 126.632 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 11728155483

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.184%

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 11728108402: -0.002%
Covered Lines: 32329
Relevant Lines: 32752

💛 - Coveralls

Copy link

github-actions bot commented Oct 14, 2024

Tachometer results

Chrome

action-menu permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 960 kB 145.20ms - 149.51ms - faster ✔
5% - 8%
7.44ms - 13.31ms
branch 917 kB 155.73ms - 159.72ms slower ❌
5% - 9%
7.44ms - 13.31ms
-

test-directive permalink

Version Bytes Avg Time vs remote vs branch
npm latest 917 kB 73.27ms - 74.81ms - faster ✔
6% - 9%
4.98ms - 7.49ms
branch 874 kB 79.29ms - 81.27ms slower ❌
7% - 10%
4.98ms - 7.49ms
-

test-lazy permalink

Version Bytes Avg Time vs remote vs branch
npm latest 916 kB 71.85ms - 73.45ms - faster ✔
7% - 10%
5.40ms - 7.88ms
branch 873 kB 78.33ms - 80.24ms slower ❌
7% - 11%
5.40ms - 7.88ms
-

test-open-close-directive permalink

Version Bytes Avg Time vs remote vs branch
npm latest 1.09 MB 1878.90ms - 1882.22ms - unsure 🔍
-0% - +0%
-1.02ms - +3.24ms
branch 1.05 MB 1878.12ms - 1880.79ms unsure 🔍
-0% - +0%
-3.24ms - +1.02ms
-

test-open-close permalink

Version Bytes Avg Time vs remote vs branch
npm latest 1.09 MB 1883.27ms - 1886.07ms - unsure 🔍
-0% - +0%
-2.87ms - +1.03ms
branch 1.05 MB 1884.24ms - 1886.94ms unsure 🔍
-0% - +0%
-1.03ms - +2.87ms
-

breadcrumbs permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 979 kB 536.95ms - 545.38ms - unsure 🔍
-2% - +0%
-8.54ms - +2.30ms
branch 936 kB 540.87ms - 547.69ms unsure 🔍
-0% - +2%
-2.30ms - +8.54ms
-

combobox permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 1 MB 42.42ms - 42.91ms - faster ✔
2% - 3%
0.69ms - 1.34ms
branch 957 kB 43.47ms - 43.90ms slower ❌
2% - 3%
0.69ms - 1.34ms
-

light-dom-test permalink

Version Bytes Avg Time vs remote vs branch
npm latest 1 MB 398.87ms - 408.68ms - faster ✔
0% - 3%
0.85ms - 12.73ms
branch 957 kB 407.22ms - 413.92ms slower ❌
0% - 3%
0.85ms - 12.73ms
-

menu permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 741 kB 209.24ms - 219.02ms - unsure 🔍
-4% - +1%
-8.67ms - +2.59ms
branch 716 kB 214.38ms - 219.95ms unsure 🔍
-1% - +4%
-2.59ms - +8.67ms
-

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 795 kB 74.05ms - 75.24ms - faster ✔
9% - 12%
7.45ms - 10.25ms
branch 771 kB 82.23ms - 84.77ms slower ❌
10% - 14%
7.45ms - 10.25ms
-

picker permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 817 kB 504.19ms - 516.13ms - faster ✔
2% - 5%
9.65ms - 24.57ms
branch 774 kB 522.80ms - 531.74ms slower ❌
2% - 5%
9.65ms - 24.57ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 742 kB 76.95ms - 78.50ms - faster ✔
3% - 6%
2.50ms - 4.51ms
branch 717 kB 80.59ms - 81.87ms slower ❌
3% - 6%
2.50ms - 4.51ms
-
Firefox

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 795 kB 159.30ms - 166.90ms - faster ✔
6% - 11%
11.01ms - 20.43ms
branch 771 kB 176.04ms - 181.60ms slower ❌
7% - 13%
11.01ms - 20.43ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 742 kB 162.31ms - 171.25ms - unsure 🔍
-8% - +0%
-14.13ms - +0.45ms
branch 717 kB 167.87ms - 179.37ms unsure 🔍
-0% - +9%
-0.45ms - +14.13ms
-

@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?

@Rocss Rocss requested review from Rajdeepc and blunteshwar October 21, 2024 08:20
@Rocss
Copy link
Contributor Author

Rocss commented Oct 23, 2024

@Rajdeepc @blunteshwar @rubencarvalho any more feedback here?
I'd like to close this ticket this sprint if possible, thanks!

@rubencarvalho rubencarvalho merged commit a791bd1 into main Nov 7, 2024
43 of 45 checks passed
@rubencarvalho rubencarvalho deleted the rocss/4805 branch November 7, 2024 20:49
nikkimk pushed a commit that referenced this pull request Nov 19, 2024
… IME (#4817)

* fix(number-field): allow only numeric characters for Japanese, Simplified/Traditional Chinese IME

* chore: remove forgotten console log

* chore: implement code review

* chore: con't emit input event on invalid characters

* chore: implement code review

---------

Co-authored-by: rmanole <rmanole@adobe.com>
Co-authored-by: Rúben Carvalho <rubcar@sapo.pt>
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