Skip to content

Conversation

@metonym
Copy link
Collaborator

@metonym metonym commented Oct 19, 2025

Supports #2285

DataTable already supports generics for row data, which greatly enhances DX (local IDE typeahead, type safety, etc..).

This PR updates ComboBox with a similar feature. It now supports TypeScript generics on items, allowing type-safe access to custom item properties in callbacks, events, and slots.

This is highly useful when storing/passing additional properties on items.

This change should be backward compatible; omitting the generic type parameter defaults to ComboBoxItem.

Example Usage

The price and category fields are automatically inferred.

<script lang="ts">
  import { ComboBox } from "carbon-components-svelte";

  const items = [
    { id: "1", text: "Laptop", price: 999, category: "Electronics" },
    { id: "2", text: "Phone", price: 599, category: "Electronics" },
    { id: "3", text: "Desk", price: 299, category: "Furniture" },
  ];
</script>

<ComboBox
  {items}
  titleText="Products"
  placeholder="Select a product"
  on:select={(e) => {
    console.log("selected:", e.detail.selectedItem);
  }}
  let:item
>
  {@const { text, price, category } = item}
  <div>
    <strong>{text}</strong> - ${price}
    <span>({category})</span>
  </div>
</ComboBox>
Screenshot 2025-11-08 at 9 24 36 AM

@metonym metonym force-pushed the master branch 3 times, most recently from 234c1f9 to e774974 Compare October 28, 2025 20:48
@metonym metonym force-pushed the metonym/generic-components branch 5 times, most recently from 2e7526b to 5952ffb Compare November 8, 2025 17:28
@metonym metonym marked this pull request as ready for review November 8, 2025 17:28
@metonym metonym force-pushed the metonym/generic-components branch from 5952ffb to 650d347 Compare November 8, 2025 17:31
@metonym metonym force-pushed the metonym/generic-components branch from 650d347 to ba89976 Compare November 8, 2025 17:32
@metonym metonym merged commit d76fe9e into master Nov 8, 2025
7 checks passed
@metonym metonym deleted the metonym/generic-components branch November 8, 2025 17: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.

1 participant