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

bug(number-field): update number-field value on pressing "enter" #3638

Merged
merged 3 commits into from
Sep 29, 2023

Conversation

TarunAdobe
Copy link
Contributor

Description

If you type in a number larger than the max attribute and press "return", it should change the number to the max.
i.e. The value inside the number-field should update on pressing "return" however right now it only happens when the input is blurred out.

Related issue(s)

Motivation and context

If you type in a number larger than the max attribute and press "return", it doesn't always change the number. However, the number is always changed when the input is blurred. In addition, the number is never changed when format-options is used, and the number is only changed the first time you press "return" even without format-options.

How has this been tested?

  • Test case 1
    1. Go here
    2. Do this
  • Test case 2
    1. Go here
    2. Do this

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.

@github-actions
Copy link

github-actions bot commented Sep 12, 2023

Tachometer results

Chrome

number-field permalink

Version Bytes Avg Time vs remote vs branch
npm latest 622 kB 270.12ms - 275.32ms - unsure 🔍
-1% - +2%
-1.88ms - +4.82ms
branch 618 kB 269.14ms - 273.36ms unsure 🔍
-2% - +1%
-4.82ms - +1.88ms
-

slider permalink

Version Bytes Avg Time vs remote vs branch
npm latest 461 kB 214.69ms - 218.65ms - unsure 🔍
-2% - +1%
-4.65ms - +1.31ms
branch 457 kB 216.11ms - 220.57ms unsure 🔍
-1% - +2%
-1.31ms - +4.65ms
-
Firefox

number-field permalink

Version Bytes Avg Time vs remote vs branch
npm latest 622 kB 422.96ms - 444.36ms - unsure 🔍
-2% - +5%
-8.41ms - +20.17ms
branch 618 kB 418.31ms - 437.25ms unsure 🔍
-5% - +2%
-20.17ms - +8.41ms
-

slider permalink

Version Bytes Avg Time vs remote vs branch
npm latest 461 kB 347.83ms - 362.09ms - unsure 🔍
-6% - +1%
-23.18ms - +4.78ms
branch 457 kB 352.14ms - 376.18ms unsure 🔍
-1% - +7%
-4.78ms - +23.18ms
-

@TarunAdobe TarunAdobe force-pushed the bug/number-field-max-value branch from 2360ef8 to 5a426e4 Compare September 13, 2023 09:32
@TarunAdobe TarunAdobe self-assigned this Sep 13, 2023
@TarunAdobe TarunAdobe marked this pull request as ready for review September 13, 2023 09:33
@blunteshwar
Copy link
Collaborator

@TarunAdobe some VRTs are failing. Can you look at them

@TarunAdobe TarunAdobe force-pushed the bug/number-field-max-value branch 2 times, most recently from 7808521 to bc7ffca Compare September 20, 2023 05:33
Rajdeepc
Rajdeepc previously approved these changes Sep 20, 2023
@@ -340,6 +340,13 @@ export class NumberField extends TextfieldBase {
new Event('change', { bubbles: true, composed: true })
);
break;
case 'Enter':
event.preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default that you're preventing here?

We haven't gotten to Form Association for these Custom Elements, but in the future, were this associated to a form, there would be some expectation that Enter would submit the form by default.

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 point! I have removed the event.preventDefault() and I've updated the few tests with the current behaviour expectations

this.inputElement.value = this.formattedValue;
this.dispatchEvent(
new Event('change', { bubbles: true, composed: true })
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good are there any tests that would be beneficial to add in support of this going forward?

Copy link
Contributor

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

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

Really like what you've settled on here! A couple of extra cases to confirm and tests to duplicate before we can merge this, but it's really starting to shape up.

packages/number-field/src/NumberField.ts Outdated Show resolved Hide resolved
@@ -400,7 +405,11 @@ export class NumberField extends TextfieldBase {
}
}
this.value = value;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line will trigger the setter. Will the following lines never accidentally dispatch a second change event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no because in the setter we are updated the lastCommittedValue which will cause the check on the line 409 to fail making sure there is not second change event

packages/number-field/test/number-field.test.ts Outdated Show resolved Hide resolved
packages/number-field/test/number-field.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

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

This looks good to go. I'm gonna rebase this to main and make sure CI is still happy before merging.

One thing to keep an eye on, the tests that you touched were a tiny bit flaky before and this may increase the negative effect of that flakiness in future work. If we see a jump in transient failures, let's make time in a team sync to discuss ways to make these tests more stable.

@Westbrook Westbrook force-pushed the bug/number-field-max-value branch from 65bc5ae to 0e21010 Compare September 29, 2023 12:42
@Westbrook Westbrook merged commit 649eb2f into main Sep 29, 2023
8 checks passed
@Westbrook Westbrook deleted the bug/number-field-max-value branch September 29, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Issues related to accessibility Component: Slider ready-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: sp-number-field doesn't always limit to max value upon return
4 participants