Skip to content

Commit

Permalink
fix: fix ref issue on arrow scroll (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman authored Jun 14, 2024
1 parent 4c9fbdc commit eea0851
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/ArrowScroll.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Children,
type ComponentProps,
type ReactElement,
cloneElement,
useEffect,
useRef,
Expand Down Expand Up @@ -82,7 +81,7 @@ const scroll = (
}
}

function ArrowScroll({ children, ...props }: { children?: ReactElement }) {
function ArrowScroll({ children, ...props }: { children?: any }) {
const containerRef = useRef<HTMLElement>(undefined)
const [showLeftArrow, setShowLeftArrow] = useState(false)
const [showRightArrow, setShowRightArrow] = useState(false)
Expand Down Expand Up @@ -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
}
}
},
})}
</ComponentWrapperSC>
)
Expand Down

0 comments on commit eea0851

Please sign in to comment.