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(combobox): allow numeric values and trigger change event on keybo… #4405

Merged
merged 3 commits into from
May 8, 2024

Conversation

Rocss
Copy link
Contributor

@Rocss Rocss commented May 7, 2024

…ard selection

Description

This PR aims to fix two issues when navigating in the Combobox using the keyboard.

Related issue(s)

Motivation and context

  1. When using numeric values for Combobox options (representing IDs or quantities), an error is thrown in the console and the list does not scroll
  2. When pressing "Enter" after navigating to an option, the change event is not triggered, as it is triggered on mouse interactions.

How has this been tested?

  • Test case 1
    1. Go here
    2. Click on the Combobox input
    3. Press Arrow-Down
    4. Continue pressing Arrow-Down/Up to navigate in the options list
    5. Observe that no errors are thrown in the browser console
  • Test case 2
    1. Go here
    2. Click on the Combobox input
    3. Press Arrow-Down
    4. Press Enter
    5. The change event is triggered, event.target.value is 55

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 May 7, 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 221.457 kB 210.554 kB 🏆 210.737 kB
Scripts 53.652 kB 48.214 kB 48.192 kB 🏆
Stylesheet 35.057 kB 30.519 kB 🏆 30.718 kB
Document 5.917 kB 5.188 kB 🏆 5.191 kB
Font 126.831 kB 126.633 kB 🏆 126.636 kB

Request Count

Category Latest Main Branch
Total 45 45 45
Scripts 37 37 37
Stylesheet 5 5 5
Document 1 1 1
Font 2 2 2

Copy link

github-actions bot commented May 7, 2024

Tachometer results

Chrome

combobox permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 709 kB 36.72ms - 37.98ms - unsure 🔍
-4% - +0%
-1.68ms - +0.02ms
branch 696 kB 37.61ms - 38.75ms unsure 🔍
-0% - +5%
-0.02ms - +1.68ms
-

light-dom-test permalink

Version Bytes Avg Time vs remote vs branch
npm latest 709 kB 388.86ms - 400.29ms - faster ✔
2% - 6%
9.50ms - 25.30ms
branch 696 kB 406.53ms - 417.43ms slower ❌
2% - 6%
9.50ms - 25.30ms
-
Firefox

combobox permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 709 kB 63.81ms - 68.59ms - slower ❌
5% - 13%
2.84ms - 7.80ms
branch 696 kB 60.22ms - 61.54ms faster ✔
5% - 12%
2.84ms - 7.80ms
-

light-dom-test permalink

Version Bytes Avg Time vs remote vs branch
npm latest 709 kB 730.01ms - 752.71ms - slower ❌
2% - 6%
17.32ms - 42.28ms
branch 696 kB 706.37ms - 716.75ms faster ✔
2% - 6%
17.32ms - 42.28ms
-

@Rocss Rocss marked this pull request as ready for review May 7, 2024 09:34
@Rocss Rocss linked an issue May 7, 2024 that may be closed by this pull request
1 task
@@ -211,6 +214,7 @@ export class Combobox extends Textfield {
return;
}
this.value = this.activeDescendant.itemText;
this.handleChange();
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like selectDescendant() is only used when the Enter key is pressed. I wonder if we can get the same, but slightly better, simply by this.activeDescendant.click(). In theory, this would trigger the lifecycle of the <sp-menu> and hit all of the appropriate change, etc. pathways ensuing all selections were "the same".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.activeDescendant.click() does not really work, since it is defined as MenuItem | ComboboxOption, but what can be done and works is similar to what's inside scrollToActiveDescendant, but instead of scroll you click.

@@ -354,4 +354,31 @@ describe('Combobox accessibility', () => {

expect(el.open).to.be.false;
});
it('manages keyboard navigation and selection', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include testing for numeric values, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! 😄 More than what I already added in packages/combobox/test/combobox.data.test.ts?
Or a combination of numeric values + selection testing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, somehow I didn't see that test. I think we just need to press Enter on something there to confirm it's fully hit the getElementById() path, and then this will be good to go!

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 combined them into one test since it was 90% the same, just the data was different. 🙈

Comment on lines +218 to +222
const activeEl = this.shadowRoot.getElementById(
this.activeDescendant.value
);
if (activeEl) {
activeEl.click();
}
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 change also trigger the code in line 216 to happen in handleInput, as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah indeed.
It does not trigger handleInput, buuuut it does trigger handleMenuChange which does this.value = selected?.itemText || ''; which is same thing as line 216.

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.

Awesome! Gonna catch up main and then merge when Ci is green. Many thanks 🙇🏼

@Westbrook Westbrook force-pushed the rocss/numeric-combobox-fix branch from 9d59470 to 8af69ea Compare May 8, 2024 15:25
@Westbrook Westbrook merged commit 235ae7c into main May 8, 2024
49 checks passed
@Westbrook Westbrook deleted the rocss/numeric-combobox-fix branch May 8, 2024 15:38
TarunAdobe pushed a commit that referenced this pull request May 10, 2024
#4405)

* fix(combobox): allow numeric values and trigger change event on keyboard selection

* chore: call click method to trigger change

* chore: update tests

---------

Co-authored-by: rmanole <rmanole@adobe.com>
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]: Combobox throws errors when options with numeric values are provided
2 participants