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 4 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
10 changes: 6 additions & 4 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, MoreProps } from '../interface';
import { getRemovable } from '../util';
import AddButton from './AddButton';

Expand All @@ -18,7 +18,7 @@ export interface OperationNodeProps {
tabBarGutter?: number;
activeKey: string;
mobile: boolean;
moreIcon?: React.ReactNode;
more?: MoreProps
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
more?: MoreProps
more?: MoreProps;

moreTransitionName?: string;
editable?: EditableConfig;
locale?: TabsLocale;
Expand All @@ -36,7 +36,7 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
tabs,
locale,
mobile,
moreIcon = 'More',
more: moreProps = {},
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 All @@ -52,6 +52,8 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
const [open, setOpen] = useState(false);
const [selectedKey, setSelectedKey] = useState<string>(null);

const { icon: moreIcon = 'More', trigger = 'hover' } = moreProps;

const popupId = `${id}-more-popup`;
const dropdownPrefix = `${prefixCls}-dropdown`;
const selectedItemId = selectedKey !== null ? `${popupId}-${selectedKey}` : null;
Expand Down Expand Up @@ -190,14 +192,14 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
<Dropdown
prefixCls={dropdownPrefix}
overlay={menu}
trigger={['hover']}
visible={tabs.length ? open : false}
transitionName={moreTransitionName}
onVisibleChange={setOpen}
overlayClassName={classNames(overlayClassName, popupClassName)}
mouseEnterDelay={0.1}
mouseLeaveDelay={0.1}
getPopupContainer={getPopupContainer}
{...moreProps}
>
<button
type="button"
Expand Down
3 changes: 2 additions & 1 deletion src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useVisibleRange from '../hooks/useVisibleRange';
import type {
AnimatedConfig,
EditableConfig,
MoreProps,
OnTabScroll,
RenderTabBar,
SizeInfo,
Expand All @@ -38,7 +39,7 @@ export interface TabNavListProps {
animated?: AnimatedConfig;
extra?: TabBarExtraContent;
editable?: EditableConfig;
moreIcon?: React.ReactNode;
more?: MoreProps;
moreTransitionName?: string;
mobile: boolean;
tabBarGutter?: number;
Expand Down
7 changes: 4 additions & 3 deletions src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { GetIndicatorSize } from './hooks/useIndicator';
import type {
AnimatedConfig,
EditableConfig,
MoreProps,
OnTabScroll,
RenderTabBar,
Tab,
Expand Down Expand Up @@ -64,7 +65,7 @@ export interface TabsProps
locale?: TabsLocale;

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

export type TriggerProps = {
trigger?: 'hover' | 'click';
}
export type moreIcon = React.ReactNode;
export type MoreProps = {
icon?: moreIcon,
} & Omit<DropdownProps, 'children'>;

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

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, more: {icon: '...', trigger: '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