diff --git a/web/components/dropdowns/cycle/index.tsx b/web/components/dropdowns/cycle/index.tsx index d59cb8b83..305d72a58 100644 --- a/web/components/dropdowns/cycle/index.tsx +++ b/web/components/dropdowns/cycle/index.tsx @@ -8,6 +8,7 @@ import { cn } from "@/helpers/common.helper"; import { useCycle } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; // components import { DropdownButton } from "../buttons"; // icons @@ -84,6 +85,7 @@ export const CycleDropdown: React.FC = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); return ( = (props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); const disabledDays: Matcher[] = []; if (minDate) disabledDays.push({ before: minDate }); diff --git a/web/components/dropdowns/estimate.tsx b/web/components/dropdowns/estimate.tsx index 1219a7011..ca0da92d1 100644 --- a/web/components/dropdowns/estimate.tsx +++ b/web/components/dropdowns/estimate.tsx @@ -9,6 +9,7 @@ import { cn } from "@/helpers/common.helper"; import { useApplication, useEstimate } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; // components import { DropdownButton } from "./buttons"; // helpers @@ -146,6 +147,7 @@ export const EstimateDropdown: React.FC = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); useEffect(() => { if (isOpen && inputRef.current) { diff --git a/web/components/dropdowns/member/index.tsx b/web/components/dropdowns/member/index.tsx index edc2b604e..8d59e6335 100644 --- a/web/components/dropdowns/member/index.tsx +++ b/web/components/dropdowns/member/index.tsx @@ -7,6 +7,7 @@ import { cn } from "@/helpers/common.helper"; import { useMember } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; // components import { DropdownButton } from "../buttons"; import { BUTTON_VARIANTS_WITH_TEXT } from "../constants"; @@ -84,6 +85,7 @@ export const MemberDropdown: React.FC = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); return ( = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); const comboboxProps: any = { value, diff --git a/web/components/dropdowns/priority.tsx b/web/components/dropdowns/priority.tsx index 49dd5b2c5..2f845b64e 100644 --- a/web/components/dropdowns/priority.tsx +++ b/web/components/dropdowns/priority.tsx @@ -10,6 +10,7 @@ import { ISSUE_PRIORITIES } from "@/constants/issue"; import { cn } from "@/helpers/common.helper"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; import { usePlatformOS } from "@/hooks/use-platform-os"; // icons // helpers @@ -360,12 +361,13 @@ export const PriorityDropdown: React.FC = (props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); const ButtonToRender = BORDER_BUTTON_VARIANTS.includes(buttonVariant) ? BorderButton : BACKGROUND_BUTTON_VARIANTS.includes(buttonVariant) - ? BackgroundButton - : TransparentButton; + ? BackgroundButton + : TransparentButton; useEffect(() => { if (isOpen && inputRef.current) { diff --git a/web/components/dropdowns/state.tsx b/web/components/dropdowns/state.tsx index 7ba69d1ce..ec783882c 100644 --- a/web/components/dropdowns/state.tsx +++ b/web/components/dropdowns/state.tsx @@ -9,6 +9,7 @@ import { cn } from "@/helpers/common.helper"; import { useApplication, useProjectState } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; // components import { DropdownButton } from "./buttons"; // icons @@ -128,6 +129,7 @@ export const StateDropdown: React.FC = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); useEffect(() => { if (isOpen && inputRef.current) { diff --git a/web/components/issues/select/label.tsx b/web/components/issues/select/label.tsx index 32bcc4160..4aee1a0de 100644 --- a/web/components/issues/select/label.tsx +++ b/web/components/issues/select/label.tsx @@ -9,6 +9,7 @@ import { IssueLabelsList } from "@/components/ui"; import { useLabel } from "@/hooks/store"; import { useDropdownKeyDown } from "@/hooks/use-dropdown-key-down"; import useOutsideClickDetector from "@/hooks/use-outside-click-detector"; +import useOutsideKeydownDetector from "@/hooks/use-outside-keydown-detector"; // ui // icons @@ -76,6 +77,7 @@ export const IssueLabelSelect: React.FC = observer((props) => { }; useOutsideClickDetector(dropdownRef, handleClose); + useOutsideKeydownDetector(dropdownRef, handleClose); useEffect(() => { if (isDropdownOpen && inputRef.current) { diff --git a/web/hooks/use-outside-keydown-detector.tsx b/web/hooks/use-outside-keydown-detector.tsx new file mode 100644 index 000000000..3de4f1c79 --- /dev/null +++ b/web/hooks/use-outside-keydown-detector.tsx @@ -0,0 +1,19 @@ +import React, { useEffect } from "react"; + +const useOutsideKeydownDetector = (ref: React.RefObject, callback: () => void) => { + const handleKeyDown = (event: KeyboardEvent) => { + if (ref.current && !ref.current.contains(event.target as Node)) { + callback(); + } + }; + + useEffect(() => { + document.addEventListener("keydown", handleKeyDown); + + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }); +}; + +export default useOutsideKeydownDetector;