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

WB-1675: Implement Combobox component with single selection #2221

Merged
merged 5 commits into from
Aug 27, 2024

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented May 1, 2024

Summary:

This is the first PR associated to the Combobox implementation. It includes the
basic structure of the Combobox component with single selection support.

Combobox Implementation Plan:

  1. WB-1589: Add Listbox component with Single and Multiple selection support #2216
  2. Add Combobox component with Single selection support. [CURRENT]
  3. Add multiple selection support to Combobox component.
  4. Add autocomplete support to Combobox component.
  5. Add async/dynamic support to Combobox component.

Issue: https://khanacademy.atlassian.net/browse/WB-1675

Test plan:

Verify that the new Component component works as expected and that the new
documentation is accurate.

/?path=/docs/packages-dropdown-combobox--docs

https://5e1bf4b385e3fb0020b7073c-mzmurnrasq.chromatic.com/?path=/docs/packages-dropdown-combobox--docs

Keyboard navigation:

  • Focus on the input field to open the Listbox.
  • Use the ArrowDown / ArrowUp keys to navigate through the options.
  • Use the Enter key to select an option.
  • Use the Escape key to close the Listbox.
  • Verify that the selected option is displayed in the input field.
Screen.Recording.2024-05-01.at.3.10.07.PM.mov

@jandrade jandrade self-assigned this May 1, 2024
Copy link

changeset-bot bot commented May 1, 2024

🦋 Changeset detected

Latest commit: 379fee2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@khanacademy/wonder-blocks-dropdown Minor
@khanacademy/wonder-blocks-icon-button Minor
@khanacademy/wonder-blocks-birthday-picker Patch
@khanacademy/wonder-blocks-banner Patch
@khanacademy/wonder-blocks-modal Patch
@khanacademy/wonder-blocks-popover Patch
@khanacademy/wonder-blocks-search-field Patch
@khanacademy/wonder-blocks-tooltip Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented May 1, 2024

Size Change: +1.35 kB (+1.39%)

Total Size: 98.2 kB

Filename Size Change
packages/wonder-blocks-dropdown/dist/es/index.js 15.5 kB +1.35 kB (+9.54%) ⚠️
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.78 kB
packages/wonder-blocks-banner/dist/es/index.js 1.52 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.72 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 1.13 kB
packages/wonder-blocks-button/dist/es/index.js 4.28 kB
packages/wonder-blocks-cell/dist/es/index.js 2.24 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.3 kB
packages/wonder-blocks-core/dist/es/index.js 3.66 kB
packages/wonder-blocks-data/dist/es/index.js 6.34 kB
packages/wonder-blocks-form/dist/es/index.js 5.34 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-i18n/dist/es/index.js 4.6 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.23 kB
packages/wonder-blocks-icon/dist/es/index.js 1.06 kB
packages/wonder-blocks-labeled-field/dist/es/index.js 72 B
packages/wonder-blocks-layout/dist/es/index.js 1.94 kB
packages/wonder-blocks-link/dist/es/index.js 2.53 kB
packages/wonder-blocks-modal/dist/es/index.js 5.51 kB
packages/wonder-blocks-pill/dist/es/index.js 1.64 kB
packages/wonder-blocks-popover/dist/es/index.js 4.85 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.54 kB
packages/wonder-blocks-switch/dist/es/index.js 2.09 kB
packages/wonder-blocks-testing/dist/es/index.js 3.94 kB
packages/wonder-blocks-theming/dist/es/index.js 693 B
packages/wonder-blocks-timing/dist/es/index.js 1.8 kB
packages/wonder-blocks-tokens/dist/es/index.js 1.74 kB
packages/wonder-blocks-toolbar/dist/es/index.js 855 B
packages/wonder-blocks-tooltip/dist/es/index.js 6.91 kB
packages/wonder-blocks-typography/dist/es/index.js 1.48 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented May 1, 2024

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-tctnhwhcfo.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 343
Tests with visual changes 2
Total stories 432
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 343

Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 98.56851% with 7 lines in your changes missing coverage. Please review.

Project coverage is 94.67%. Comparing base (371749e) to head (379fee2).
Report is 45 commits behind head on main.

Files Patch % Lines
...wonder-blocks-dropdown/src/components/combobox.tsx 98.74% 5 Missing ⚠️
...s/wonder-blocks-dropdown/src/hooks/use-listbox.tsx 90.47% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2221      +/-   ##
==========================================
+ Coverage   94.44%   94.67%   +0.23%     
==========================================
  Files         248      249       +1     
  Lines       29387    29855     +468     
  Branches     2414     1806     -608     
==========================================
+ Hits        27754    28265     +511     
+ Misses       1629     1573      -56     
- Partials        4       17      +13     
Files Coverage Δ
.../wonder-blocks-dropdown/src/components/listbox.tsx 100.00% <100.00%> (ø)
...-blocks-icon-button/src/components/icon-button.tsx 100.00% <100.00%> (ø)
...s/wonder-blocks-dropdown/src/hooks/use-listbox.tsx 98.36% <90.47%> (-0.75%) ⬇️
...wonder-blocks-dropdown/src/components/combobox.tsx 98.74% <98.74%> (ø)

... and 41 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 371749e...379fee2. Read the comment docs.

@jandrade jandrade marked this pull request as ready for review May 7, 2024 14:36
@khan-actions-bot khan-actions-bot requested a review from a team May 7, 2024 14:36
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/gold-houses-own.md, .changeset/swift-peaches-hunt.md, __docs__/wonder-blocks-dropdown/combobox.stories.tsx, packages/wonder-blocks-dropdown/src/index.ts, packages/wonder-blocks-dropdown/src/components/combobox.tsx, packages/wonder-blocks-dropdown/src/components/listbox.tsx, packages/wonder-blocks-dropdown/src/hooks/use-listbox.tsx, packages/wonder-blocks-icon-button/src/components/icon-button.tsx, packages/wonder-blocks-dropdown/src/components/__tests__/combobox.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

github-actions bot commented May 7, 2024

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (f5a3ab0) and published all packages with changesets to npm.

You can install the packages in webapp by running:

./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2221"

Packages can also be installed manually by running:

yarn add @khanacademy/wonder-blocks-<package-name>@PR2221

Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

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

Very nice work - looks good to me!

@jandrade jandrade merged commit ea506e8 into main Aug 27, 2024
16 checks passed
@jandrade jandrade deleted the combobox-single branch August 27, 2024 21:16
jandrade added a commit that referenced this pull request Aug 27, 2024
## Summary:

Create the multiple version that displays the selected values as individual Pill
components that can be deleted/unchecked.

Added a new hook to manage keyboard navigation for the multiple selection logic.

### Combobox Implementation Plan:

1. #2216
2. #2221
3. **Add multiple selection support to `Combobox` component.[CURRENT]**
4. Improve accessibility support on Combobox (labels, aria-live).
5. Add autocomplete support to `Combobox` component.
6. Add async/dynamic support to `Combobox` component.


Issue: https://khanacademy.atlassian.net/browse/WB-1676

## Test plan:

1. Navigate to: /?path=/docs/packages-dropdown-combobox--docs#multiple%20selection
2. Use the multi-select version of the Combobox.
3. Navigate using the keyboard.
4. Verify that you can select multiple options and can delete selected options using the keyboard.

### Keyboard navigation instructions (when the combobox is focused):
- `Arrow Up | Arrow Down`: to navigate the listbox options
- `Arrow left | Arrow right`: to navigate the selected options (pills displayed before the input)
- `Backspace`: removes the last pill in the stack
- `Enter`:
  - When the listbox is focused: unselects an option from the list
  - When the pills are focused: removes the currently focused pill and unselects the associated option in the listbox.


https://github.com/Khan/wonder-blocks/assets/843075/7ad1476a-df73-42e0-87a3-2e7bf80c6b77

Author: jandrade

Reviewers: jeresig

Required Reviewers:

Approved By: jeresig

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Lint (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏭️  dependabot

Pull Request URL: #2223
jandrade added a commit that referenced this pull request Aug 28, 2024
…eaders (#2225)

## Summary:

This PR focuses on bringing a better accessibility experience by adding a live region to announce the different combobox statuses:
- When the visual focus changes in the listbox.
- When the visual focus changes in the selected options (multi-select mode).
- When it is closed.
- Describing a state for the focused option. e.g. `selected`, `disabled`.

### Combobox Implementation Plan:

1. #2216
2. #2221
3. #2223
4. **Improve accessibility support on Combobox (labels, aria-live).[CURRENT]**
5. Add autocomplete support to `Combobox` component.
6. Add async/dynamic support to `Combobox` component.


Issue: https://khanacademy.atlassian.net/browse/WB-1676

## Test plan:

Turn on Voice Over and use Safari:

### Single Selection:

1. Navigate to: /iframe.html?args=&id=packages-dropdown-combobox--single-select-combobox&viewMode=story
2. Using the keyboard, open the listbox by focusing on the input then pressing `arrow down`.
3. Verify that the Screen Reader announces the selected item (`Pear selected, 3 of 9. 9 results available`).
4. Navigate on the listbox by using the arrow keys.
5. Verify that it announces the currently focused item (e.g. `Strawberry disabled, 2 of 9. 9 results available`).
6. Using the keyboard, Select one of the enabled options.
7. Verify that it announces the selection (e.g. `Apple selected`) and the listbox is closed.

https://github.com/user-attachments/assets/dd7f6173-e00b-4a96-bed3-c5b0df6c2fbd


### Multiple Selection:

1. Navigate to /iframe.html?args=&id=packages-dropdown-combobox--multiple-selection&viewMode=story
2. Using the keyboard, open the listbox by focusing on the input then pressing `arrow down`.
3. Verify that the Screen Reader announces the selected item (`Pear selected, 3 of 9. 9 results available`).
4. Navigate on the listbox by using the arrow keys.
5. Verify that it announces the currently focused item (e.g. `Strawberry disabled, 2 of 9. 9 results available`).
6. Using the keyboard, Select one of the enabled options (pressing `Enter` on the focused option).
7. Verify that it announces the selection (e.g. `Apple selected, 5 of 9. 9 results available.`) and the listbox remains open).
9. Press arrow left or arrow right to move visual focus to the selected pills.
10. Verify that the focus moves to one of the pills and SR announces that (e.g. `Grape focused, 3 of 3. 3 selected options`).

https://github.com/user-attachments/assets/80a6eabc-ef82-4828-8c18-ed8e05bf8fee

Author: jandrade

Reviewers: beaesguerra, jandrade

Required Reviewers:

Approved By: beaesguerra

Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test (ubuntu-latest, 20.x, 2/2), ✅ Test (ubuntu-latest, 20.x, 1/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Lint (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ⏭️  Chromatic - Skip on Release PR (changesets), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ gerald, ⏭️  dependabot

Pull Request URL: #2225
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.

3 participants