Fix sidebar scroll into view

This commit is contained in:
Gregory Schier
2024-08-15 09:09:18 -07:00
parent 6bc697e4a7
commit a7f0fadeae
2 changed files with 6 additions and 5 deletions

View File

@@ -610,7 +610,6 @@ function SidebarItem({
children,
}: SidebarItemProps) {
const ref = useRef<HTMLLIElement>(null);
useScrollIntoView(ref.current, selected);
const [, connectDrop] = useDrop<DragItem, void>(
{
@@ -670,6 +669,8 @@ function SidebarItem({
const isActive = activeRequest?.id === itemId;
const createDropdownItems = useCreateDropdownItems({ folderId: itemId });
useScrollIntoView(ref.current, isActive);
const handleSubmitNameEdit = useCallback(
(el: HTMLInputElement) => {
if (itemModel === 'http_request') {

View File

@@ -1,9 +1,9 @@
import { useEffect } from 'react';
export function useScrollIntoView<T extends HTMLElement>(node: T | null, active: boolean) {
export function useScrollIntoView<T extends HTMLElement>(node: T | null, enabled: boolean) {
useEffect(() => {
if (active) {
node?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
if (enabled) {
node?.scrollIntoView({ block: 'nearest' });
}
}, [active, node]);
}, [enabled, node]);
}