Skip to content

Commit eea0851

Browse files
authored
fix: fix ref issue on arrow scroll (#610)
1 parent 4c9fbdc commit eea0851

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/components/ArrowScroll.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Children,
33
type ComponentProps,
4-
type ReactElement,
54
cloneElement,
65
useEffect,
76
useRef,
@@ -82,7 +81,7 @@ const scroll = (
8281
}
8382
}
8483

85-
function ArrowScroll({ children, ...props }: { children?: ReactElement }) {
84+
function ArrowScroll({ children, ...props }: { children?: any }) {
8685
const containerRef = useRef<HTMLElement>(undefined)
8786
const [showLeftArrow, setShowLeftArrow] = useState(false)
8887
const [showRightArrow, setShowRightArrow] = useState(false)
@@ -117,7 +116,16 @@ function ArrowScroll({ children, ...props }: { children?: ReactElement }) {
117116
/>
118117
{cloneElement(Children.only(children), {
119118
onScroll: checkScroll,
120-
ref: containerRef,
119+
ref: (node: HTMLElement) => {
120+
containerRef.current = node
121+
if (children.ref) {
122+
if (typeof children.ref === 'function') {
123+
children.ref(node)
124+
} else if (children.ref) {
125+
children.ref.current = node
126+
}
127+
}
128+
},
121129
})}
122130
</ComponentWrapperSC>
123131
)

0 commit comments

Comments
 (0)