mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix(list-box): correct button/description translations based on selection count
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:
parent
9b61af0306
commit
5c332bae5e
4 changed files with 75 additions and 13 deletions
|
@ -60,13 +60,35 @@ describe("ComboBox", () => {
|
|||
},
|
||||
});
|
||||
|
||||
const clearButton = screen.getByRole("button", { name: /clear/i });
|
||||
const clearButton = screen.getByRole("button", {
|
||||
name: "Clear selected item",
|
||||
});
|
||||
await user.click(clearButton);
|
||||
|
||||
expect(consoleLog).toHaveBeenCalledWith("clear", expect.any(String));
|
||||
expect(screen.getByRole("textbox")).toHaveValue("");
|
||||
});
|
||||
|
||||
it("should use custom translations when translateWithId is provided", () => {
|
||||
const customTranslations = {
|
||||
clearSelection: "Remove selected item",
|
||||
clearAll: "Remove all items",
|
||||
} as const;
|
||||
|
||||
render(ComboBox, {
|
||||
props: {
|
||||
selectedId: "1",
|
||||
value: "Email",
|
||||
translateWithIdSelection: (id) => customTranslations[id],
|
||||
},
|
||||
});
|
||||
|
||||
const clearButton = screen.getByRole("button", {
|
||||
name: "Remove selected item",
|
||||
});
|
||||
expect(clearButton).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should handle disabled state", () => {
|
||||
render(ComboBox, { props: { disabled: true } });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue