Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 容器可视宽度低于整体宽度进行切换时,下拉菜单无法显示隐藏的内容 #697

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
addSizeValue,
// Operation
operationSizeValue,
containerExcludeExtraSizeValue,
activeKey,
{ ...props, tabs },
);

Expand Down
7 changes: 7 additions & 0 deletions src/hooks/useVisibleRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default function useVisibleRange(
tabContentSizeValue: number,
addNodeSizeValue: number,
operationNodeSizeValue: number,
containerExcludeExtraSizeValue: number,
activeKey: string,
{ tabs, tabPosition, rtl }: { tabs: Tab[] } & TabNavListProps,
): [visibleStart: number, visibleEnd: number] {
let charUnit: 'width' | 'height';
Expand All @@ -34,6 +36,11 @@ export default function useVisibleRange(
return [0, 0];
}

if (containerExcludeExtraSizeValue < tabContentSizeValue) {
const filterIndex = tabs.findIndex(item => (item.tabKey || item.key) === activeKey);
return [filterIndex, filterIndex]
}
Copy link
Member

@afc163 afc163 Jan 27, 2024

Choose a reason for hiding this comment

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

能帮忙补一个测试用例不?

Copy link
Author

Choose a reason for hiding this comment

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

我看overflow.test.tsx中的should calculate hidden tabs correctly用例应该可以覆盖这种情况吧

Copy link
Member

Choose a reason for hiding this comment

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

那为啥原来的测试用例没挂呢?

Copy link
Author

Choose a reason for hiding this comment

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

那我试着补一个


const len = tabs.length;
let endIndex = len;
for (let i = 0; i < len; i += 1) {
Expand Down
35 changes: 35 additions & 0 deletions tests/overflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,41 @@ describe('Tabs.Overflow', () => {
expect(document.querySelector('.rc-tabs-dropdown-menu').textContent).not.toContain('miu');
});

it('should be displayed in the minimum width dropdown menu', () => {
const items = [
{
key: '1',
label: 'Tab 1',
children: 'Tab 1',
},
{
key: '2',
label: 'Tab 2',
children: 'Tab 2',
},
{
key: '3',
label: 'Tab 3',
children: 'Tab 3',
},
]
jest.useFakeTimers();

const { container } = render(getTabs({ items, activeKey: items[0].key, style: { width: '70px' } }));

act(() => {
jest.runAllTimers();
});
fireEvent.click(container.querySelectorAll('.rc-tabs-tab')[1])

fireEvent.mouseEnter(container.querySelector('.rc-tabs-nav-more'));
act(() => {
jest.runAllTimers();
});

expect(document.querySelector('.rc-tabs-dropdown-menu').textContent).not.toContain(items[1].key);
});

it('should support getPopupContainer', () => {
const div = document.createElement('div');
document.body.appendChild(div);
Expand Down
Loading