From 8b02e79f44d0989d3420643bcbcc6470a89ce0f6 Mon Sep 17 00:00:00 2001 From: IsKaros <819481291@qq.com> Date: Fri, 23 Aug 2024 21:47:29 +0800 Subject: [PATCH] fix:doesn't scroll when use scrollTo with `top` zero (#1180) Co-authored-by: KAROS\81948 Co-authored-by: afc163 --- docs/examples/scrollY.tsx | 9 +++++++++ src/Table.tsx | 3 ++- tests/Scroll.spec.jsx | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/examples/scrollY.tsx b/docs/examples/scrollY.tsx index 8b30845f5..52622db5f 100644 --- a/docs/examples/scrollY.tsx +++ b/docs/examples/scrollY.tsx @@ -59,6 +59,15 @@ const Test = () => { > Scroll To key 9 + ( // Native scroll const { index, top, key } = config; - if (top) { + // * 考虑top为0的情况 + if (top || top === 0) { scrollBodyRef.current?.scrollTo({ top, }); diff --git a/tests/Scroll.spec.jsx b/tests/Scroll.spec.jsx index 122d79664..387e6cd5f 100644 --- a/tests/Scroll.spec.jsx +++ b/tests/Scroll.spec.jsx @@ -135,4 +135,22 @@ describe('Table.Scroll', () => { domSpy.mockRestore(); vi.useRealTimers(); }); + + it('trigger inner scrollTo when set `top` 0 after render', () => { + let isTriggerScroll = false; + spyElementPrototypes(HTMLElement, { + scrollTo: _ => { + isTriggerScroll = true; + }, + }); + + const tRef = React.createRef(); + + const wrapper = mount(createTable({ ref: tRef })); + + tRef.current.scrollTo({ + top: 0, + }); + expect(isTriggerScroll).toEqual(true); + }); });