carbon-components-svelte/tests/ComboBox/ComboBox.test.svelte
Eric Liu 1a5f2d8e67
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`
2025-03-23 11:28:06 -07:00

54 lines
1.4 KiB
Svelte

<script lang="ts">
import { ComboBox } from "carbon-components-svelte";
import type { ComponentProps } from "svelte";
export let items: ComponentProps<ComboBox>["items"] = [
{ id: "0", text: "Slack" },
{ id: "1", text: "Email" },
{ id: "2", text: "Fax" },
];
export let selectedId: ComponentProps<ComboBox>["selectedId"] = undefined;
export let value = "";
export let disabled = false;
export let invalid = false;
export let warn = false;
export let light = false;
export let open = false;
export let titleText = "Contact";
export let placeholder = "Select contact method";
export let invalidText = "";
export let warnText = "";
export let helperText = "";
export let size: "sm" | "xl" | undefined = undefined;
export let shouldFilterItem: ComponentProps<ComboBox>["shouldFilterItem"] = (
item,
value,
) => item.text.toLowerCase().includes(value.toLowerCase());
export let translateWithIdSelection: ComponentProps<ComboBox>["translateWithIdSelection"] =
undefined;
</script>
<ComboBox
{disabled}
{helperText}
{invalid}
{invalidText}
{items}
{light}
{open}
{placeholder}
{selectedId}
{size}
{titleText}
{value}
{warn}
{warnText}
{shouldFilterItem}
{translateWithIdSelection}
on:select={(e) => {
console.log("select", e.detail);
}}
on:clear={(e) => {
console.log("clear", e.type);
}}
/>