fix: inconsistency for create label, select label getting closed on select (#1085)

This commit is contained in:
Dakshesh Jain 2023-05-19 19:12:24 +05:30 committed by GitHub
parent 406f02737f
commit ddeafc0695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 55 deletions

View File

@ -30,7 +30,7 @@ type Props = {
const defaultValues: Partial<IState> = { const defaultValues: Partial<IState> = {
name: "", name: "",
color: "#000000", color: "#858E96",
}; };
export const CreateLabelModal: React.FC<Props> = ({ isOpen, projectId, handleClose }) => { export const CreateLabelModal: React.FC<Props> = ({ isOpen, projectId, handleClose }) => {
@ -44,7 +44,6 @@ export const CreateLabelModal: React.FC<Props> = ({ isOpen, projectId, handleClo
watch, watch,
control, control,
reset, reset,
setError,
} = useForm<IIssueLabels>({ } = useForm<IIssueLabels>({
defaultValues, defaultValues,
}); });
@ -109,13 +108,13 @@ export const CreateLabelModal: React.FC<Props> = ({ isOpen, projectId, handleClo
{({ open, close }) => ( {({ open, close }) => (
<> <>
<Popover.Button <Popover.Button
className={`group inline-flex items-center rounded-sm bg-brand-surface-2 text-base font-medium hover:text-brand-base focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 ${ className={`group inline-flex items-center rounded-sm py-2 text-base font-medium hover:text-brand-base focus:outline-none ${
open ? "text-brand-base" : "text-brand-secondary" open ? "text-brand-base" : "text-brand-secondary"
}`} }`}
> >
{watch("color") && watch("color") !== "" && ( {watch("color") && watch("color") !== "" && (
<span <span
className="ml-2 h-4 w-4 rounded" className="ml-2 h-5 w-5 rounded"
style={{ style={{
backgroundColor: watch("color") ?? "black", backgroundColor: watch("color") ?? "black",
}} }}
@ -161,7 +160,7 @@ export const CreateLabelModal: React.FC<Props> = ({ isOpen, projectId, handleClo
type="text" type="text"
id="name" id="name"
name="name" name="name"
placeholder="Enter name" placeholder="Label title"
autoComplete="off" autoComplete="off"
error={errors.name} error={errors.name}
register={register} register={register}

View File

@ -14,6 +14,8 @@ import { Popover, Transition } from "@headlessui/react";
import issuesService from "services/issues.service"; import issuesService from "services/issues.service";
// ui // ui
import { Input, PrimaryButton, SecondaryButton } from "components/ui"; import { Input, PrimaryButton, SecondaryButton } from "components/ui";
// icons
import { ChevronDownIcon } from "@heroicons/react/24/outline";
// types // types
import { IIssueLabels } from "types"; import { IIssueLabels } from "types";
// fetch-keys // fetch-keys
@ -28,7 +30,7 @@ type Props = {
const defaultValues: Partial<IIssueLabels> = { const defaultValues: Partial<IIssueLabels> = {
name: "", name: "",
color: "#ff0000", color: "#858E96",
}; };
type Ref = HTMLDivElement; type Ref = HTMLDivElement;
@ -113,7 +115,7 @@ export const CreateUpdateLabelInline = forwardRef<Ref, Props>(function CreateUpd
}`} }`}
ref={ref} ref={ref}
> >
<div className="h-8 w-8 flex-shrink-0"> <div className="flex-shrink-0">
<Popover className="relative z-10 flex h-full w-full items-center justify-center"> <Popover className="relative z-10 flex h-full w-full items-center justify-center">
{({ open }) => ( {({ open }) => (
<> <>
@ -128,6 +130,12 @@ export const CreateUpdateLabelInline = forwardRef<Ref, Props>(function CreateUpd
backgroundColor: watch("color"), backgroundColor: watch("color"),
}} }}
/> />
<ChevronDownIcon
className={`ml-2 h-5 w-5 group-hover:text-brand-secondary ${
open ? "text-gray-600" : "text-gray-400"
}`}
aria-hidden="true"
/>
</Popover.Button> </Popover.Button>
<Transition <Transition
@ -153,7 +161,7 @@ export const CreateUpdateLabelInline = forwardRef<Ref, Props>(function CreateUpd
)} )}
</Popover> </Popover>
</div> </div>
<div className="flex w-full flex-col justify-center"> <div className="flex flex-1 flex-col justify-center">
<Input <Input
type="text" type="text"
id="labelName" id="labelName"

View File

@ -329,7 +329,7 @@ const SinglePage: NextPage = () => {
</div> </div>
<div className="flex w-full flex-wrap gap-1"> <div className="flex w-full flex-wrap gap-1">
{pageDetails.labels.length > 0 ? ( {pageDetails.labels.length > 0 && (
<> <>
{pageDetails.labels.map((labelId) => { {pageDetails.labels.map((labelId) => {
const label = labels?.find((label) => label.id === labelId); const label = labels?.find((label) => label.id === labelId);
@ -362,6 +362,8 @@ const SinglePage: NextPage = () => {
</div> </div>
); );
})} })}
</>
)}
<CustomSearchSelect <CustomSearchSelect
customButton={ customButton={
<button <button
@ -369,28 +371,10 @@ const SinglePage: NextPage = () => {
className="flex items-center gap-1 rounded-sm bg-brand-surface-2 p-1.5 text-xs" className="flex items-center gap-1 rounded-sm bg-brand-surface-2 p-1.5 text-xs"
> >
<PlusIcon className="h-3.5 w-3.5" /> <PlusIcon className="h-3.5 w-3.5" />
{pageDetails.labels.length <= 0 && <span>Add Label</span>}
</button> </button>
} }
value={pageDetails.labels} value={pageDetails.labels}
onChange={(val: string[]) => partialUpdatePage({ labels_list: val })}
options={options}
multiple
noChevron
/>
</>
) : (
<CustomSearchSelect
customButton={
<button
type="button"
className="flex items-center gap-1 rounded-sm bg-brand-surface-2 px-3 py-1.5 text-xs"
>
<PlusIcon className="h-3 w-3" />
Add label
</button>
}
value={pageDetails.labels}
onChange={(val: string[]) => partialUpdatePage({ labels_list: val })}
footerOption={ footerOption={
<button <button
type="button" type="button"
@ -405,11 +389,11 @@ const SinglePage: NextPage = () => {
</span> </span>
</button> </button>
} }
onChange={(val: string[]) => partialUpdatePage({ labels_list: val })}
options={options} options={options}
multiple multiple
noChevron noChevron
/> />
)}
</div> </div>
</div> </div>
<div className="flex items-center"> <div className="flex items-center">