Skip to content

Commit

Permalink
fix: scroll position should be reset when all tabs are removed (#332)
Browse files Browse the repository at this point in the history
* reset scroll when there is no active tab

* add test: scroll to 0 when activeKey is null
  • Loading branch information
rinick authored Nov 16, 2020
1 parent f6b8589 commit cadd00a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,13 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {

// ========================= Scroll ========================
function scrollToTab(key = activeKey) {
const tabOffset = tabOffsets.get(key);

if (!tabOffset) return;
const tabOffset = tabOffsets.get(key) || {
width: 0,
height: 0,
left: 0,
right: 0,
top: 0,
};

if (tabPositionTopOrBottom) {
// ============ Align with top & bottom ============
Expand Down
9 changes: 9 additions & 0 deletions tests/overflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ describe('Tabs.Overflow', () => {
expect(getTransformX(wrapper)).toEqual(-20);
expect(onTabScroll).toHaveBeenCalledWith({ direction: 'left' });

// scroll to 0 when activeKey is null
onTabScroll.mockReset();
wrapper.setProps({ activeKey: null });
act(() => {
jest.runAllTimers();
wrapper.update();
});
expect(getTransformX(wrapper)).toEqual(0);

jest.useRealTimers();
});

Expand Down

1 comment on commit cadd00a

@vercel
Copy link

@vercel vercel bot commented on cadd00a Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.