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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-multi-select-component",
"version": "2.0.5",
"version": "2.0.6",
"description": "Simple and lightweight multiple selection dropdown component with checkboxes, search and select-all",
"author": "Harsh Zalavadiya",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export interface ISelectProps {
overrideStrings?: { [key: string]: string };
labelledBy: string;
className?: string;
onMenuToggle?;
}
9 changes: 8 additions & 1 deletion src/multi-select/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import useOutsideClick from "@rooks/use-outside-click";
import { css } from "goober";
import React, { useRef, useState } from "react";
import React, { useRef, useState, useEffect } from "react";

import Arrow from "./arrow";
import Loading from "./loading";
Expand All @@ -18,6 +18,7 @@ interface IDropdownProps {
disabled?: boolean;
shouldToggleOnHover?: boolean;
labelledBy?: string;
onMenuToggle?;
}

const PanelContainer = css({
Expand Down Expand Up @@ -75,6 +76,7 @@ const Dropdown = ({
disabled,
shouldToggleOnHover,
labelledBy,
onMenuToggle,
}: IDropdownProps) => {
const [expanded, setExpanded] = useState(false);
const [hasFocus, setHasFocus] = useState(false);
Expand All @@ -83,6 +85,11 @@ const Dropdown = ({

useOutsideClick(wrapper, () => setExpanded(false));

/* eslint-disable react-hooks/exhaustive-deps */
useEffect(() => {
onMenuToggle && onMenuToggle(expanded);
}, [expanded]);

const handleKeyDown = e => {
switch (e.which) {
case 27: // Escape
Expand Down
2 changes: 2 additions & 0 deletions src/multi-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const MultiSelect = ({
disableSearch,
filterOptions,
labelledBy,
onMenuToggle,
}: ISelectProps) => {
const nvalue = value || [];
return (
Expand All @@ -66,6 +67,7 @@ const MultiSelect = ({
}}
disabled={disabled}
labelledBy={labelledBy}
onMenuToggle={onMenuToggle}
>
<DropdownHeader
value={nvalue}
Expand Down
1 change: 1 addition & 0 deletions stories/default.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const toStorybook = () => {
value={selected}
disabled={boolean("disabled", false)}
onChange={setSelected}
onMenuToggle={(s)=>{console.log("Select Toggle: ", s)}}
labelledBy={text("labelledBy", "Select Fruits")}
className={text("className", "multi-select")}
/>
Expand Down