fix: add scroll into view when editing label in settings page (#660)

This commit is contained in:
Saheb Giri 2023-03-31 18:31:01 +05:30 committed by GitHub
parent d596e41d4d
commit abe34ad7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import React, { useEffect } from "react"; import React, { forwardRef, useEffect } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
@ -31,12 +31,12 @@ const defaultValues: Partial<IIssueLabels> = {
color: "#ff0000", color: "#ff0000",
}; };
export const CreateUpdateLabelInline: React.FC<Props> = ({ type Ref = HTMLDivElement;
labelForm,
setLabelForm, export const CreateUpdateLabelInline = forwardRef<Ref, Props>(function CreateUpdateLabelInline(
isUpdating, { labelForm, setLabelForm, isUpdating, labelToUpdate },
labelToUpdate, ref
}) => { ) {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
@ -109,9 +109,10 @@ export const CreateUpdateLabelInline: React.FC<Props> = ({
return ( return (
<div <div
className={`flex items-center gap-2 rounded-[10px] border bg-white p-5 ${ className={`flex items-center gap-2 scroll-m-8 rounded-[10px] border bg-white p-5 ${
labelForm ? "" : "hidden" labelForm ? "" : "hidden"
}`} }`}
ref={ref}
> >
<div className="h-8 w-8 flex-shrink-0"> <div className="h-8 w-8 flex-shrink-0">
<Popover className="relative z-10 flex h-full w-full items-center justify-center rounded-xl bg-gray-200"> <Popover className="relative z-10 flex h-full w-full items-center justify-center rounded-xl bg-gray-200">
@ -187,4 +188,4 @@ export const CreateUpdateLabelInline: React.FC<Props> = ({
)} )}
</div> </div>
); );
}; });

View File

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useState, useRef } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
@ -46,6 +46,8 @@ const LabelsSettings: NextPage<UserAuth> = (props) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
const scollToRef = useRef<HTMLDivElement>(null);
const { data: projectDetails } = useSWR( const { data: projectDetails } = useSWR(
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
workspaceSlug && projectId workspaceSlug && projectId
@ -128,6 +130,7 @@ const LabelsSettings: NextPage<UserAuth> = (props) => {
setLabelForm={setLabelForm} setLabelForm={setLabelForm}
isUpdating={isUpdating} isUpdating={isUpdating}
labelToUpdate={labelToUpdate} labelToUpdate={labelToUpdate}
ref={scollToRef}
/> />
)} )}
<> <>
@ -142,7 +145,12 @@ const LabelsSettings: NextPage<UserAuth> = (props) => {
key={label.id} key={label.id}
label={label} label={label}
addLabelToGroup={() => addLabelToGroup(label)} addLabelToGroup={() => addLabelToGroup(label)}
editLabel={editLabel} editLabel={(label) => {
editLabel(label);
scollToRef.current?.scrollIntoView({
behavior: "smooth",
});
}}
handleLabelDelete={handleLabelDelete} handleLabelDelete={handleLabelDelete}
/> />
); );
@ -153,7 +161,12 @@ const LabelsSettings: NextPage<UserAuth> = (props) => {
label={label} label={label}
labelChildren={children} labelChildren={children}
addLabelToGroup={addLabelToGroup} addLabelToGroup={addLabelToGroup}
editLabel={editLabel} editLabel={(label) => {
editLabel(label);
scollToRef.current?.scrollIntoView({
behavior: "smooth",
});
}}
handleLabelDelete={handleLabelDelete} handleLabelDelete={handleLabelDelete}
/> />
); );