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 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
13 changes: 6 additions & 7 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,8 +18,7 @@ export interface OperationNodeProps {
tabBarGutter?: number;
activeKey: string;
mobile: boolean;
moreIcon?: React.ReactNode;
moreTransitionName?: string;
more?: MoreProps;
editable?: EditableConfig;
locale?: TabsLocale;
removeAriaLabel?: string;
Expand All @@ -36,8 +35,7 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
tabs,
locale,
mobile,
moreIcon = 'More',
moreTransitionName,
more: moreProps = {},
style,
className,
editable,
Expand All @@ -52,6 +50,8 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
const [open, setOpen] = useState(false);
const [selectedKey, setSelectedKey] = useState<string>(null);

const { icon: moreIcon = 'More' } = moreProps;

const popupId = `${id}-more-popup`;
const dropdownPrefix = `${prefixCls}-dropdown`;
const selectedItemId = selectedKey !== null ? `${popupId}-${selectedKey}` : null;
Expand Down Expand Up @@ -190,14 +190,13 @@ 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
4 changes: 2 additions & 2 deletions 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,8 +39,7 @@ export interface TabNavListProps {
animated?: AnimatedConfig;
extra?: TabBarExtraContent;
editable?: EditableConfig;
moreIcon?: React.ReactNode;
moreTransitionName?: string;
more?: MoreProps;
mobile: boolean;
tabBarGutter?: number;
renderTabBar?: RenderTabBar;
Expand Down
10 changes: 4 additions & 6 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,9 +65,8 @@ export interface TabsProps
locale?: TabsLocale;

// Icons
moreIcon?: React.ReactNode;
more?: MoreProps;
/** @private Internal usage. Not promise will rename in future */
moreTransitionName?: string;
popupClassName?: string;
indicator?: {
size?: GetIndicatorSize;
Expand All @@ -90,8 +90,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
tabBarStyle,
tabBarExtraContent,
locale,
moreIcon,
moreTransitionName,
more,
destroyInactiveTabPane,
renderTabBar,
onChange,
Expand Down Expand Up @@ -173,8 +172,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
...sharedProps,
editable,
locale,
moreIcon,
moreTransitionName,
more,
tabBarGutter,
onTabClick: onInternalTabClick,
onTabScroll,
Expand Down
12 changes: 10 additions & 2 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 Expand Up @@ -36,8 +45,7 @@ type RenderTabBarProps = {
mobile: boolean;
editable: EditableConfig;
locale: TabsLocale;
moreIcon: React.ReactNode;
moreTransitionName: string;
more: MoreProps,
tabBarGutter: number;
onTabClick: (key: string, e: React.MouseEvent | React.KeyboardEvent) => void;
onTabScroll: OnTabScroll;
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