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): update IME change detection #4672

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

rubencarvalho
Copy link
Collaborator

@rubencarvalho rubencarvalho commented Aug 16, 2024

Description

This PR resolves an issue in Safari where multi-byte characters were being improperly converted, resulting in NaN and updates the function responsible for triggering the change event to ensure it behaves consistently across all supported browsers.

Related issue(s)

Motivation and context

sp-number-field + Safari + IME were in need of some love.

How has this been tested?

  • Storybook actions

    1. Open the Safari browser
    2. Go to the deployed/locahost /storybook/index.html?path=/story/number-field--default
    3. In your system settings, select "Japanese" as the IME
    4. Type any number in the sp-number-field component
    5. Observe the actions tab on Enter keypress and blur for the expected behaviour
  • Did it pass in Desktop?

  • Did it pass in Mobile?

  • Did it pass in iPad (simulator)?

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 Aug 16, 2024

Tachometer results

Chrome

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 537 kB 68.13ms - 71.62ms - faster ✔
8% - 13%
6.05ms - 10.58ms
branch 514 kB 76.74ms - 79.64ms slower ❌
8% - 15%
6.05ms - 10.58ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 493 kB 77.90ms - 79.91ms - faster ✔
1% - 5%
1.08ms - 4.01ms
branch 470 kB 80.38ms - 82.51ms slower ❌
1% - 5%
1.08ms - 4.01ms
-
Firefox

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 537 kB 151.04ms - 158.00ms - faster ✔
6% - 10%
9.17ms - 17.43ms
branch 514 kB 165.59ms - 170.05ms slower ❌
6% - 11%
9.17ms - 17.43ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 493 kB 163.47ms - 168.89ms - faster ✔
2% - 7%
2.57ms - 12.75ms
branch 470 kB 169.53ms - 178.15ms slower ❌
2% - 8%
2.57ms - 12.75ms
-

@rubencarvalho rubencarvalho force-pushed the ruben/fix-double-byte-safari-number-field branch from e4d2eec to d62623d Compare August 16, 2024 15:27
@rubencarvalho
Copy link
Collaborator Author

@rubencarvalho rubencarvalho force-pushed the ruben/fix-double-byte-safari-number-field branch from 94628ef to ef04db6 Compare August 19, 2024 07:18
@rubencarvalho rubencarvalho changed the title fix: ensure correct parsing of value fix(number-field): update IME change detection Aug 19, 2024
@rubencarvalho rubencarvalho force-pushed the ruben/fix-double-byte-safari-number-field branch from ef04db6 to c45ff1e Compare August 19, 2024 07:31
@@ -214,7 +228,13 @@ export class NumberField extends TextfieldBase {
private valueBeforeFocus: string = '';
private isIntentDecimal: boolean = false;

private convertValueToNumber(value: string): number {
private convertValueToNumber(inputValue: string): number {
// Normalize full-width characters to their ASCII equivalents
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without normalizing this value (remapping the multi-byte characters) before the input manipulation, we would get NaN.

@@ -502,6 +502,18 @@ describe('NumberField', () => {
el.value = 52;
expect(changeSpy.callCount).to.equal(0);
});
it('handles IME input correctly and dispatches change event', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test covers both the NaN case and the change event.

private setValue(value: number = this.value): void {
this.value = value;
private setValue(newValue: number = this.value): void {
// Capture previous value for accurate IME change detection
Copy link
Collaborator Author

@rubencarvalho rubencarvalho Aug 19, 2024

Choose a reason for hiding this comment

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

For IME input in Safari, the value conversion process would cause this.value and this.lastCommitedValue to be identical at the time of the comparison, even though a change had happened. So I added previousValue to hold the value of this.lastCommitedValue before the update to this.value, which fixed it! :)

@rubencarvalho rubencarvalho marked this pull request as ready for review August 19, 2024 07:47
@rubencarvalho rubencarvalho requested a review from a team as a code owner August 19, 2024 07:47
@rubencarvalho rubencarvalho merged commit de05aee into main Aug 19, 2024
55 of 58 checks passed
@rubencarvalho rubencarvalho deleted the ruben/fix-double-byte-safari-number-field branch August 19, 2024 11:38
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.

[Bug]: change event is not triggered for double byte characters on Safari
3 participants