diff --git a/README.md b/README.md index 4d0c7cc..3fc6b52 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ export default Example; | `valueRenderer` | custom dropdown header [docs](#-custom-value-renderer) | `function` | | | `ItemRenderer` | custom dropdown option [docs](#-custom-item-renderer) | `function` | | | `ClearIcon` | Custom Clear Icon for Search | `string|function` | | +| `ClearSelectedIcon` | Custom Clear Icon for Selected Items | `string|function` | | ## 🔍 Custom filter logic diff --git a/src/lib/get-string.tsx b/src/lib/get-string.tsx index b2b52d4..449f8c9 100644 --- a/src/lib/get-string.tsx +++ b/src/lib/get-string.tsx @@ -4,6 +4,7 @@ const strings = { selectAll: "Select All", search: "Search", clearSearch: "Clear Search", + clearSelected: "Clear Selected", }; export default function getString(key: string, overrideStrings?): string { diff --git a/src/lib/interfaces.ts b/src/lib/interfaces.ts index c2d8698..85806d4 100644 --- a/src/lib/interfaces.ts +++ b/src/lib/interfaces.ts @@ -35,4 +35,5 @@ export interface ISelectProps { className?: string; onMenuToggle?; ClearIcon?: string | Function; + ClearSelectedIcon?: string | Function; } diff --git a/src/multi-select/dropdown.tsx b/src/multi-select/dropdown.tsx index da5c317..ccea788 100644 --- a/src/multi-select/dropdown.tsx +++ b/src/multi-select/dropdown.tsx @@ -6,6 +6,8 @@ import { css } from "goober"; import React, { useEffect, useRef, useState } from "react"; +import getString from "../lib/get-string"; +import Cross from "../select-panel/cross"; import Arrow from "./arrow"; import Loading from "./loading"; @@ -19,6 +21,7 @@ interface IDropdownProps { labelledBy?: string; onMenuToggle?; ArrowRenderer?; + ClearSelectedIcon?; } const PanelContainer = css({ @@ -65,6 +68,13 @@ const DropdownHeading = css({ }, }); +const ClearSelectedButton = css({ + cursor: "pointer", + background: "none", + border: 0, + padding: 0, +}); + const Dropdown = ({ children, contentComponent: ContentComponent, @@ -75,6 +85,7 @@ const Dropdown = ({ labelledBy, onMenuToggle, ArrowRenderer, + ClearSelectedIcon, }: IDropdownProps) => { const [expanded, setExpanded] = useState(false); const [hasFocus, setHasFocus] = useState(false); @@ -125,6 +136,11 @@ const Dropdown = ({ const toggleExpanded = () => setExpanded(isLoading || disabled ? false : !expanded); + const handleClearSelected = (e) => { + e.stopPropagation(); + contentProps["onChange"]([]); + }; + return (
{children}
{isLoading && } + {contentProps["value"].length > 0 && ( + + )}
{expanded && ( diff --git a/src/multi-select/index.tsx b/src/multi-select/index.tsx index b24a985..41a0b70 100644 --- a/src/multi-select/index.tsx +++ b/src/multi-select/index.tsx @@ -46,6 +46,7 @@ const MultiSelect = ({ labelledBy, onMenuToggle, ClearIcon, + ClearSelectedIcon, }: ISelectProps) => { const nvalue = value || []; return ( @@ -72,6 +73,7 @@ const MultiSelect = ({ labelledBy={labelledBy} onMenuToggle={onMenuToggle} ArrowRenderer={ArrowRenderer} + ClearSelectedIcon={ClearSelectedIcon} >