Skip to content

Commit 2698d23

Browse files
fix: 🐛 clear selected icon + on search clear (#345)
1 parent d0c4ffb commit 2698d23

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/lib/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export interface ISelectProps {
2929
labelledBy: string;
3030
className?: string;
3131
onMenuToggle?;
32-
ClearIcon?: string | Function;
32+
ClearIcon?: ReactNode;
3333
debounceDuration?: number;
34-
ClearSelectedIcon?: string | Function;
34+
ClearSelectedIcon?: ReactNode;
3535
defaultIsOpen?: boolean;
3636
isOpen?: boolean;
3737
}

src/select-panel/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
* Select-all item, and the list of options.
55
*/
66
import { css } from "goober";
7-
import React, { useCallback, useEffect, useMemo, useState } from "react";
7+
import React, {
8+
useCallback,
9+
useEffect,
10+
useMemo,
11+
useRef,
12+
useState,
13+
} from "react";
814

915
import { useMultiSelect } from "../hooks/use-multi-select";
1016
import { cn } from "../lib/classnames";
@@ -69,6 +75,7 @@ const SelectPanel = () => {
6975
debounceDuration,
7076
} = useMultiSelect();
7177

78+
const searchInputRef = useRef<any>();
7279
const [searchText, setSearchText] = useState("");
7380
const [filteredOptions, setFilteredOptions] = useState(options);
7481
const [searchTextForFilter, setSearchTextForFilter] = useState("");
@@ -116,6 +123,7 @@ const SelectPanel = () => {
116123
const handleClear = () => {
117124
setSearchTextForFilter("");
118125
setSearchText("");
126+
searchInputRef?.current?.focus();
119127
};
120128

121129
const handleItemClicked = (index: number) => setFocusIndex(index);
@@ -185,6 +193,7 @@ const SelectPanel = () => {
185193
onChange={handleSearchChange}
186194
onFocus={handleSearchFocus}
187195
value={searchText}
196+
ref={searchInputRef}
188197
/>
189198
<button
190199
type="button"

stories/custom-arrow.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const ExampleCustomArrow = () => {
1414

1515
const ArrowRenderer = ({ expanded }) => <>{expanded ? "🦉" : "🦚"}</>;
1616

17+
const CustomClearIcon = () => <div>🤘</div>;
18+
1719
return (
1820
<div>
1921
<pre>{JSON.stringify(selected)}</pre>
@@ -24,6 +26,8 @@ export const ExampleCustomArrow = () => {
2426
labelledBy={text("labelledBy", "Select Fruits")}
2527
ArrowRenderer={ArrowRenderer}
2628
onMenuToggle={(isOpen) => console.log("onMenuToggle", isOpen)}
29+
ClearIcon={<CustomClearIcon />}
30+
ClearSelectedIcon={<CustomClearIcon />}
2731
/>
2832
</div>
2933
);

0 commit comments

Comments
 (0)