Skip to content

Commit 0c73cde

Browse files
authored
feat(MultiSelect): add id in props (#1256)
Signed-off-by: Kim Anh Nguyen <[email protected]>
1 parent 392ff31 commit 0c73cde

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/components/MultiSelect/MultiSelect.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const SearchExample: Story = {
5858
group: i % 2 === 0 ? "Group 1" : "Group 2",
5959
})),
6060
],
61+
id: "search-id",
6162
},
6263
};
6364

@@ -120,5 +121,6 @@ export const WithoutSorting: Story = {
120121
variant: "condensed",
121122
isSortedAlphabetically: false,
122123
hasSelectedItemsFirst: false,
124+
id: "external-id",
123125
},
124126
};

src/components/MultiSelect/MultiSelect.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type MultiSelectProps = {
3434
scrollOverflow?: boolean;
3535
isSortedAlphabetically?: boolean;
3636
hasSelectedItemsFirst?: boolean;
37+
id?: string;
3738
};
3839

3940
type ValueSet = Set<MultiSelectItem["value"]>;
@@ -203,6 +204,7 @@ export const MultiSelect: React.FC<MultiSelectProps> = ({
203204
scrollOverflow = false,
204205
isSortedAlphabetically = true,
205206
hasSelectedItemsFirst = true,
207+
id,
206208
}: MultiSelectProps) => {
207209
const buttonRef = useRef(null);
208210
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
@@ -286,7 +288,7 @@ export const MultiSelect: React.FC<MultiSelectProps> = ({
286288
externallyControlled
287289
aria-controls={dropdownId}
288290
aria-expanded={isDropdownOpen}
289-
id={inputId}
291+
id={id ?? inputId}
290292
role="combobox"
291293
aria-label={label || placeholder || "Search"}
292294
disabled={disabled}
@@ -328,6 +330,7 @@ export const MultiSelect: React.FC<MultiSelectProps> = ({
328330
}
329331
}}
330332
ref={buttonRef}
333+
id={id}
331334
>
332335
<span className="multi-select__condensed-text">
333336
{listSelected && selectedItems.length > 0

0 commit comments

Comments
 (0)