Skip to content

fix(Listbox): improve typing for ListBox#2310

Open
Bracciata wants to merge 4 commits intodevelopfrom
fix/correct-listbox-warnings
Open

fix(Listbox): improve typing for ListBox#2310
Bracciata wants to merge 4 commits intodevelopfrom
fix/correct-listbox-warnings

Conversation

@Bracciata
Copy link
Copy Markdown
Contributor

@Bracciata Bracciata commented Apr 7, 2026

Summary

Closes #1890

  • Replaces the generic PolymorphicComponent cast with a custom ListboxComponent overloaded type that properly discriminates between single-select and multi-select variants
  • Fixes TypeScript error when using <Listbox> without explicitly passing multiselect (single-select is now the default)
  • Updates @ts-expect-error comment in ActionList to reflect the actual type conflict (HTML attribute defaultValue vs ListboxValue)
  • Adds compile-time type tests to verify single-select, multi-select, and invalid usage are all typed correctly

Test plan

  • tsc passes without errors for single-select <Listbox value="foo"> (no multiselect prop)
  • tsc catches invalid usage (e.g. multiselect with a string value)
  • Existing Listbox unit tests still pass

@aws-amplify-us-east-1
Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2310.d15792l1n26ww3.amplifyapp.com

@Bracciata Bracciata marked this pull request as ready for review April 7, 2026 19:00
@Bracciata Bracciata requested a review from a team as a code owner April 7, 2026 19:00
Copilot AI review requested due to automatic review settings April 7, 2026 19:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes TypeScript typing/discrimination for the React Listbox component so single-select usage works without explicitly providing multiselect, while preserving correct multi-select typing and adding compile-time type coverage.

Changes:

  • Introduces an overloaded ListboxComponent type to discriminate single-select vs multi-select props.
  • Adds TypeScript “type test” JSX usages in Listbox tests to validate valid/invalid prop combinations at compile time.
  • Updates the @ts-expect-error explanation in ActionList to reflect the actual conflicting prop types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/components/Listbox/Listbox.tsx Replaces the broad polymorphic cast with an overloaded component type for correct single vs multi select prop discrimination.
packages/react/src/components/Listbox/index.test.tsx Adds compile-time type-check examples to ensure the Listbox overloads behave as intended.
packages/react/src/components/ActionList/ActionList.tsx Updates the @ts-expect-error comment to describe the real type conflict when spreading HTML attrs into Listbox.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/components/ActionList/ActionList.tsx Outdated
@Bracciata Bracciata enabled auto-merge (squash) April 7, 2026 19:42
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: Listbox complains about typescript types

3 participants