Skip to content

feat: add selectable variant to List component#4817

Draft
ernst-dev wants to merge 2 commits into
mainfrom
feat/selectable-list-variant
Draft

feat: add selectable variant to List component#4817
ernst-dev wants to merge 2 commits into
mainfrom
feat/selectable-list-variant

Conversation

@ernst-dev

Copy link
Copy Markdown
Member

Description

Adds an opt-in selectable variant to the List component (SIM AWSUI-62052), enabling users to choose from a set of predefined options without reaching for Table or Cards for simple selectable lists.

New (fully backward-compatible) props:

  • selectionType?: 'single' | 'multi' — enables selection. When unset, List behaves exactly as before.
  • selectedItems?: ReadonlyArray<T> — controlled selection (items matched by the id returned from renderItem).
  • onSelectionChange?: NonCancelableEventHandler<ListProps.SelectionChangeDetail<T>> — fires with the updated selectedItems.
  • isItemDisabled?: (item: T) => boolean — prevents selection of individual items.

Behavior / accessibility:

  • When selectionType is set (and the list is not sortable), the container renders as role="listbox" with aria-multiselectable for multi-select, and each item renders as role="option" with aria-selected / aria-disabled.
  • Keyboard support: roving tabindex, Up/Down/Home/End to move focus, Space/Enter to toggle selection.
  • multi renders a checkbox control (reusing the internal CheckboxIcon); single renders a radio control. Controls are aria-hidden since state is conveyed via aria-selected.
  • Selection is not combined with sortable; when both are provided, sorting takes precedence.

Test-utils: ListItemWrapper.findSelectionControl() and ListWrapper.findSelectedItems() added (dom + selectors).

Related links, issue #, if available: AWSUI-62052

How has this been tested?

  • New unit test suite src/list/__tests__/list-selectable.test.tsx (11 tests): listbox/option roles, aria-multiselectable, controlled selection, single vs multi toggle semantics, disabled items, Space/Enter toggle, roving tabindex + arrow-key focus, and sortable-takes-precedence. All 31 List unit tests pass.
  • New dev page pages/list/selectable.page.tsx demonstrating controlled single and multi selection with disabled items.
  • quick-build, eslint, and stylelint are green. Documenter API + test-utils snapshots regenerated.
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.61%. Comparing base (f97729a) to head (d2e0cdf).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/list/internal.tsx 97.18% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4817      +/-   ##
==========================================
- Coverage   97.61%   97.61%   -0.01%     
==========================================
  Files         952      952              
  Lines       30816    30891      +75     
  Branches    11318    11351      +33     
==========================================
+ Hits        30081    30154      +73     
- Misses        688      690       +2     
  Partials       47       47              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant