Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export interface ISelectProps {
labelledBy: string;
className?: string;
onMenuToggle?;
ClearIcon?: string | Function;
ClearIcon?: ReactNode;
debounceDuration?: number;
ClearSelectedIcon?: string | Function;
ClearSelectedIcon?: ReactNode;
defaultIsOpen?: boolean;
isOpen?: boolean;
}
11 changes: 10 additions & 1 deletion src/select-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* Select-all item, and the list of options.
*/
import { css } from "goober";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";

import { useMultiSelect } from "../hooks/use-multi-select";
import { cn } from "../lib/classnames";
Expand Down Expand Up @@ -69,6 +75,7 @@ const SelectPanel = () => {
debounceDuration,
} = useMultiSelect();

const searchInputRef = useRef<any>();
const [searchText, setSearchText] = useState("");
const [filteredOptions, setFilteredOptions] = useState(options);
const [searchTextForFilter, setSearchTextForFilter] = useState("");
Expand Down Expand Up @@ -116,6 +123,7 @@ const SelectPanel = () => {
const handleClear = () => {
setSearchTextForFilter("");
setSearchText("");
searchInputRef?.current?.focus();
};

const handleItemClicked = (index: number) => setFocusIndex(index);
Expand Down Expand Up @@ -185,6 +193,7 @@ const SelectPanel = () => {
onChange={handleSearchChange}
onFocus={handleSearchFocus}
value={searchText}
ref={searchInputRef}
/>
<button
type="button"
Expand Down
4 changes: 4 additions & 0 deletions stories/custom-arrow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const ExampleCustomArrow = () => {

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

const CustomClearIcon = () => <div>🤘</div>;

return (
<div>
<pre>{JSON.stringify(selected)}</pre>
Expand All @@ -24,6 +26,8 @@ export const ExampleCustomArrow = () => {
labelledBy={text("labelledBy", "Select Fruits")}
ArrowRenderer={ArrowRenderer}
onMenuToggle={(isOpen) => console.log("onMenuToggle", isOpen)}
ClearIcon={<CustomClearIcon />}
ClearSelectedIcon={<CustomClearIcon />}
/>
</div>
);
Expand Down