From f6b95b8d312b9ab22aca9081c7946b4057890130 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Thu, 2 Nov 2023 15:59:43 +0530 Subject: [PATCH] fix: Issue properties dropdown overflow issue for date and labels (#2604) --- web/components/issues/select/cycle.tsx | 3 +- web/components/issues/select/date.tsx | 121 +++++++----- web/components/issues/select/label.tsx | 248 +++++++++++++----------- web/components/issues/select/module.tsx | 3 +- 4 files changed, 205 insertions(+), 170 deletions(-) diff --git a/web/components/issues/select/cycle.tsx b/web/components/issues/select/cycle.tsx index 6d43ead41..3df4948a7 100644 --- a/web/components/issues/select/cycle.tsx +++ b/web/components/issues/select/cycle.tsx @@ -1,9 +1,8 @@ import React, { useState } from "react"; import { observer } from "mobx-react-lite"; +import { usePopper } from "react-popper"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; -// popper js -import { usePopper } from "react-popper"; // ui import { Combobox } from "@headlessui/react"; // icons diff --git a/web/components/issues/select/date.tsx b/web/components/issues/select/date.tsx index 2408bf4e1..e3c2b9614 100644 --- a/web/components/issues/select/date.tsx +++ b/web/components/issues/select/date.tsx @@ -1,5 +1,5 @@ -import React from "react"; - +import React, { Fragment, useState } from "react"; +import { usePopper } from "react-popper"; import { Popover, Transition } from "@headlessui/react"; import { CalendarDays, X } from "lucide-react"; // react-datepicker @@ -15,54 +15,73 @@ type Props = { value: string | null; }; -export const IssueDateSelect: React.FC = ({ label, maxDate, minDate, onChange, value }) => ( - - {({ close }) => ( - <> - - - {value ? ( - <> - {renderShortDateWithYearFormat(value)} - - - ) : ( - <> - - {label} - - )} - - +export const IssueDateSelect: React.FC = ({ label, maxDate, minDate, onChange, value }) => { + const [referenceElement, setReferenceElement] = React.useState(null); + const [popperElement, setPopperElement] = React.useState(null); - - - { - if (!val) onChange(""); - else onChange(renderDateFormat(val)); + const { styles, attributes } = usePopper(referenceElement, popperElement, { + placement: "bottom-start", + }); - close(); - }} - dateFormat="dd-MM-yyyy" - minDate={minDate} - maxDate={maxDate} - inline - /> - - - - )} - -); + return ( + + {({ close }) => ( + <> + +
+ {value ? ( + <> + {renderShortDateWithYearFormat(value)} + + + ) : ( + <> + + {label} + + )} +
+
+ + + +
+ { + if (!val) onChange(""); + else onChange(renderDateFormat(val)); + + close(); + }} + dateFormat="dd-MM-yyyy" + minDate={minDate} + maxDate={maxDate} + inline + /> +
+
+
+ + )} +
+ ); +}; diff --git a/web/components/issues/select/label.tsx b/web/components/issues/select/label.tsx index 6319ee207..b7a828d8f 100644 --- a/web/components/issues/select/label.tsx +++ b/web/components/issues/select/label.tsx @@ -1,7 +1,8 @@ -import React, { useState } from "react"; +import React, { Fragment, useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Combobox, Transition } from "@headlessui/react"; +import { usePopper } from "react-popper"; // services import { IssueLabelService } from "services/issue"; // ui @@ -29,6 +30,13 @@ export const IssueLabelSelect: React.FC = ({ setIsOpen, value, onChange, const router = useRouter(); const { workspaceSlug } = router.query; + const [referenceElement, setReferenceElement] = useState(null); + const [popperElement, setPopperElement] = useState(null); + + const { styles, attributes } = usePopper(referenceElement, popperElement, { + placement: "bottom-start", + }); + const { data: issueLabels } = useSWR( projectId ? PROJECT_ISSUE_LABELS(projectId) : null, workspaceSlug && projectId @@ -43,21 +51,26 @@ export const IssueLabelSelect: React.FC = ({ setIsOpen, value, onChange, onChange(val)} className="relative flex-shrink-0" multiple> {({ open }: any) => ( <> - - {value && value.length > 0 ? ( - - issueLabels?.find((l) => l.id === v)) ?? []} - length={3} - showLength - /> - - ) : ( - - - Label - - )} + +
+ {value && value.length > 0 ? ( + + issueLabels?.find((l) => l.id === v)) ?? []} + length={3} + showLength + /> + + ) : ( + + + Label + + )} +
= ({ setIsOpen, value, onChange, leaveFrom="opacity-100 translate-y-0" leaveTo="opacity-0 translate-y-1" > - +
-
- - setQuery(event.target.value)} - placeholder="Search for label..." - displayValue={(assigned: any) => assigned?.name} - /> -
-
- {issueLabels && filteredOptions ? ( - filteredOptions.length > 0 ? ( - filteredOptions.map((label) => { - const children = issueLabels?.filter((l) => l.parent === label.id); + ref={setPopperElement} + style={styles.popper} + {...attributes.popper} + > +
+ + setQuery(event.target.value)} + placeholder="Search for label..." + displayValue={(assigned: any) => assigned?.name} + /> +
+
+ {issueLabels && filteredOptions ? ( + filteredOptions.length > 0 ? ( + filteredOptions.map((label) => { + const children = issueLabels?.filter((l) => l.parent === label.id); - if (children.length === 0) { - if (!label.parent) - return ( - - `${ - active ? "bg-custom-background-80" : "" - } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-custom-text-200` - } - value={label.id} - > - {({ selected }) => ( -
-
- - {label.name} -
-
- -
-
- )} -
- ); - } else - return ( -
-
- {label.name} -
-
- {children.map((child) => ( - - `${ - active ? "bg-custom-background-80" : "" - } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-custom-text-200` - } - value={child.id} - > - {({ selected }) => ( -
-
- - {child.name} -
-
- -
+ if (children.length === 0) { + if (!label.parent) + return ( + + `${ + active ? "bg-custom-background-80" : "" + } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-custom-text-200` + } + value={label.id} + > + {({ selected }) => ( +
+
+ + {label.name}
- )} - - ))} +
+ +
+
+ )} +
+ ); + } else + return ( +
+
+ {label.name} +
+
+ {children.map((child) => ( + + `${ + active ? "bg-custom-background-80" : "" + } group flex min-w-[14rem] cursor-pointer select-none items-center gap-2 truncate rounded px-1 py-1.5 text-custom-text-200` + } + value={child.id} + > + {({ selected }) => ( +
+
+ + {child.name} +
+
+ +
+
+ )} +
+ ))} +
-
- ); - }) + ); + }) + ) : ( +

No labels found

+ ) ) : ( -

No labels found

- ) - ) : ( -

Loading...

- )} - +

Loading...

+ )} + +
diff --git a/web/components/issues/select/module.tsx b/web/components/issues/select/module.tsx index bb9117d54..c0d9c6c4c 100644 --- a/web/components/issues/select/module.tsx +++ b/web/components/issues/select/module.tsx @@ -1,9 +1,8 @@ import React, { useState } from "react"; import { observer } from "mobx-react-lite"; +import { usePopper } from "react-popper"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; -// popper js -import { usePopper } from "react-popper"; // ui import { Combobox } from "@headlessui/react"; // icons