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

feat: add overflow trigger props #706

Merged
merged 8 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/TabNavList/OperationNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Menu, { MenuItem } from 'rc-menu';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import { useEffect, useState } from 'react';
import type { EditableConfig, Tab, TabsLocale } from '../interface';
import type { EditableConfig, Tab, TabsLocale, moreTrigger } from '../interface';
import { getRemovable } from '../util';
import AddButton from './AddButton';

Expand All @@ -19,6 +19,7 @@ export interface OperationNodeProps {
activeKey: string;
mobile: boolean;
moreIcon?: React.ReactNode;
moreTrigger?: moreTrigger;
moreTransitionName?: string;
editable?: EditableConfig;
locale?: TabsLocale;
Expand All @@ -37,6 +38,7 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
locale,
mobile,
moreIcon = 'More',
moreTrigger = 'hover',
moreTransitionName,
Copy link
Member

@afc163 afc163 Mar 27, 2024

Choose a reason for hiding this comment

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

这些属性合并成:

more={{ ... }}

同时一并尝试解决 ant-design/ant-design#44858ant-design/ant-design#47507 的问题吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will Check it out later.

Copy link
Member

Choose a reason for hiding this comment

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

moreTransitionName 也可以干掉,改用 more={{ transitionName }} 支持。

style,
className,
Expand Down Expand Up @@ -190,7 +192,7 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
<Dropdown
prefixCls={dropdownPrefix}
overlay={menu}
trigger={['hover']}
trigger={[`${moreTrigger}`]}
visible={tabs.length ? open : false}
transitionName={moreTransitionName}
onVisibleChange={setOpen}
Expand Down
2 changes: 2 additions & 0 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
TabPosition,
TabSizeMap,
TabsLocale,
moreTrigger
} from '../interface';
import { genDataNodeKey, stringify } from '../util';
import AddButton from './AddButton';
Expand All @@ -39,6 +40,7 @@ export interface TabNavListProps {
extra?: TabBarExtraContent;
editable?: EditableConfig;
moreIcon?: React.ReactNode;
moreTrigger?: moreTrigger;
moreTransitionName?: string;
mobile: boolean;
tabBarGutter?: number;
Expand Down
4 changes: 4 additions & 0 deletions src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
TabBarExtraContent,
TabPosition,
TabsLocale,
moreTrigger,
} from './interface';

/**
Expand Down Expand Up @@ -65,6 +66,7 @@ export interface TabsProps

// Icons
moreIcon?: React.ReactNode;
moreTrigger?: moreTrigger;
/** @private Internal usage. Not promise will rename in future */
moreTransitionName?: string;
popupClassName?: string;
Expand All @@ -91,6 +93,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
tabBarExtraContent,
locale,
moreIcon,
moreTrigger,
moreTransitionName,
destroyInactiveTabPane,
renderTabBar,
Expand Down Expand Up @@ -174,6 +177,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
editable,
locale,
moreIcon,
moreTrigger,
moreTransitionName,
tabBarGutter,
onTabClick: onInternalTabClick,
Expand Down
2 changes: 2 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type React from 'react';
import type { TabNavListProps } from './TabNavList';
import type { TabPaneProps } from './TabPanelList/TabPane';

export type moreTrigger = 'click' | 'hover';

export type SizeInfo = [width: number, height: number];

export type TabSizeMap = Map<
Expand Down
18 changes: 18 additions & 0 deletions tests/overflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ describe('Tabs.Overflow', () => {
jest.useRealTimers();
});

it('should open dropdown on click when moreTrigger is set to click', () => {
jest.useFakeTimers();
const onChange = jest.fn();
const { container, unmount } = render(getTabs({ onChange, moreTrigger: 'click' }));
triggerResize(container);
act(() => {
jest.runAllTimers();
});
const button = container.querySelector('.rc-tabs-nav-more')
fireEvent.click(button);
act(() => {
jest.runAllTimers();
});
const dropdownOpen = container.querySelector('.rc-tabs-dropdown-open');
expect(dropdownOpen).not.toBeNull();
unmount();
});

[KeyCode.SPACE, KeyCode.ENTER].forEach(code => {
it(`keyboard with select keycode: ${code}`, () => {
jest.useFakeTimers();
Expand Down
Loading