Skip to content

Commit

Permalink
fix: sort multiselect input label values (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermakowski authored Feb 9, 2024
1 parent 7e30def commit 98e3fa3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/components/MultiSelect/MultiSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ it("sorts grouped options alphabetically", async () => {
checkGroupOrder("Group 2", ["other A", "other B"]);
});

it("sorts input field value alphabetically", async () => {
const itemA = { label: "item A", value: 1 };
const itemB = { label: "item B", value: 2 };

render(
<MultiSelect
items={[itemA, itemB]}
selectedItems={[itemB, itemA]}
variant="condensed"
/>,
);

expect(screen.getByRole("combobox")).toHaveTextContent("item A, item B");
});

it("hides group title when no items match the search query", async () => {
const itemsWithGroup = [
{ label: "item one", value: 1, group: "Group 1" },
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export const MultiSelect: React.FC<MultiSelectProps> = ({
.filter((selectedItem) =>
items.some((item) => item.value === selectedItem.value),
)
.sort(sortAlphabetically)
.map((el) => el.label)
.join(", ");
return (
Expand Down

0 comments on commit 98e3fa3

Please sign in to comment.