Skip to content

Commit cadd00a

Browse files
authored
fix: scroll position should be reset when all tabs are removed (#332)
* reset scroll when there is no active tab * add test: scroll to 0 when activeKey is null
1 parent f6b8589 commit cadd00a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/TabNavList/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,13 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
207207

208208
// ========================= Scroll ========================
209209
function scrollToTab(key = activeKey) {
210-
const tabOffset = tabOffsets.get(key);
211-
212-
if (!tabOffset) return;
210+
const tabOffset = tabOffsets.get(key) || {
211+
width: 0,
212+
height: 0,
213+
left: 0,
214+
right: 0,
215+
top: 0,
216+
};
213217

214218
if (tabPositionTopOrBottom) {
215219
// ============ Align with top & bottom ============

tests/overflow.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ describe('Tabs.Overflow', () => {
276276
expect(getTransformX(wrapper)).toEqual(-20);
277277
expect(onTabScroll).toHaveBeenCalledWith({ direction: 'left' });
278278

279+
// scroll to 0 when activeKey is null
280+
onTabScroll.mockReset();
281+
wrapper.setProps({ activeKey: null });
282+
act(() => {
283+
jest.runAllTimers();
284+
wrapper.update();
285+
});
286+
expect(getTransformX(wrapper)).toEqual(0);
287+
279288
jest.useRealTimers();
280289
});
281290

0 commit comments

Comments
 (0)