-
Notifications
You must be signed in to change notification settings - Fork 211
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
fix(number-field): update IME change detection #4672
Conversation
Tachometer resultsChromenumber-field permalinkbasic-test
slider permalinktest-basic
Firefoxnumber-field permalinkbasic-test
slider permalinktest-basic
|
e4d2eec
to
d62623d
Compare
94628ef
to
ef04db6
Compare
ef04db6
to
c45ff1e
Compare
@@ -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 |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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! :)
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 thechange
event to ensure it behaves consistently across all supported browsers.Related issue(s)
change
event is not triggered for double byte characters on Safari #4579Motivation and context
sp-number-field
+ Safari + IME were in need of some love.How has this been tested?
Storybook actions
/storybook/index.html?path=/story/number-field--default
sp-number-field
componentactions
tab onEnter
keypress andblur
for the expected behaviourDid it pass in Desktop?
Did it pass in Mobile?
Did it pass in iPad (simulator)?
Types of changes
Checklist
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
.