mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:38:29 +02:00
Fix sidebar scroll into view
This commit is contained in:
@@ -610,7 +610,6 @@ function SidebarItem({
|
|||||||
children,
|
children,
|
||||||
}: SidebarItemProps) {
|
}: SidebarItemProps) {
|
||||||
const ref = useRef<HTMLLIElement>(null);
|
const ref = useRef<HTMLLIElement>(null);
|
||||||
useScrollIntoView(ref.current, selected);
|
|
||||||
|
|
||||||
const [, connectDrop] = useDrop<DragItem, void>(
|
const [, connectDrop] = useDrop<DragItem, void>(
|
||||||
{
|
{
|
||||||
@@ -670,6 +669,8 @@ function SidebarItem({
|
|||||||
const isActive = activeRequest?.id === itemId;
|
const isActive = activeRequest?.id === itemId;
|
||||||
const createDropdownItems = useCreateDropdownItems({ folderId: itemId });
|
const createDropdownItems = useCreateDropdownItems({ folderId: itemId });
|
||||||
|
|
||||||
|
useScrollIntoView(ref.current, isActive);
|
||||||
|
|
||||||
const handleSubmitNameEdit = useCallback(
|
const handleSubmitNameEdit = useCallback(
|
||||||
(el: HTMLInputElement) => {
|
(el: HTMLInputElement) => {
|
||||||
if (itemModel === 'http_request') {
|
if (itemModel === 'http_request') {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useEffect } from 'react';
|
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(() => {
|
useEffect(() => {
|
||||||
if (active) {
|
if (enabled) {
|
||||||
node?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
node?.scrollIntoView({ block: 'nearest' });
|
||||||
}
|
}
|
||||||
}, [active, node]);
|
}, [enabled, node]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user