fix(list-box): correct button/description translations based on selection count (#2139)

The `ListBoxSelection` component now properly handles
translations for the clear button based on the selected items:

- Fix `buttonLabel` and `description` to use the same translation logic
- Add tests for custom translations in both `ComboBox` and `MultiSelect`
This commit is contained in:
Eric Liu 2025-03-23 11:28:06 -07:00 committed by GitHub
commit 1a5f2d8e67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 75 additions and 13 deletions

View file

@ -1,13 +1,13 @@
<script lang="ts">
import { ComboBox } from "carbon-components-svelte";
import type { ComboBoxItem } from "carbon-components-svelte/ComboBox/ComboBox.svelte";
import type { ComponentProps } from "svelte";
export let items: ComboBoxItem[] = [
export let items: ComponentProps<ComboBox>["items"] = [
{ id: "0", text: "Slack" },
{ id: "1", text: "Email" },
{ id: "2", text: "Fax" },
];
export let selectedId: string | undefined = undefined;
export let selectedId: ComponentProps<ComboBox>["selectedId"] = undefined;
export let value = "";
export let disabled = false;
export let invalid = false;
@ -20,8 +20,12 @@
export let warnText = "";
export let helperText = "";
export let size: "sm" | "xl" | undefined = undefined;
export let shouldFilterItem = (item: ComboBoxItem, value: string) =>
item.text.toLowerCase().includes(value.toLowerCase());
export let shouldFilterItem: ComponentProps<ComboBox>["shouldFilterItem"] = (
item,
value,
) => item.text.toLowerCase().includes(value.toLowerCase());
export let translateWithIdSelection: ComponentProps<ComboBox>["translateWithIdSelection"] =
undefined;
</script>
<ComboBox
@ -40,6 +44,7 @@
{warn}
{warnText}
{shouldFilterItem}
{translateWithIdSelection}
on:select={(e) => {
console.log("select", e.detail);
}}