From eea0851e9fb2891c2cdb7f432525349bafcb76e0 Mon Sep 17 00:00:00 2001 From: Jake Laderman Date: Fri, 14 Jun 2024 16:01:14 -0400 Subject: [PATCH] fix: fix ref issue on arrow scroll (#610) --- src/components/ArrowScroll.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/ArrowScroll.tsx b/src/components/ArrowScroll.tsx index ff309be3..3bdbe68f 100644 --- a/src/components/ArrowScroll.tsx +++ b/src/components/ArrowScroll.tsx @@ -1,7 +1,6 @@ import { Children, type ComponentProps, - type ReactElement, cloneElement, useEffect, useRef, @@ -82,7 +81,7 @@ const scroll = ( } } -function ArrowScroll({ children, ...props }: { children?: ReactElement }) { +function ArrowScroll({ children, ...props }: { children?: any }) { const containerRef = useRef(undefined) const [showLeftArrow, setShowLeftArrow] = useState(false) const [showRightArrow, setShowRightArrow] = useState(false) @@ -117,7 +116,16 @@ function ArrowScroll({ children, ...props }: { children?: ReactElement }) { /> {cloneElement(Children.only(children), { onScroll: checkScroll, - ref: containerRef, + ref: (node: HTMLElement) => { + containerRef.current = node + if (children.ref) { + if (typeof children.ref === 'function') { + children.ref(node) + } else if (children.ref) { + children.ref.current = node + } + } + }, })} )