Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/eslint-plugin-unic…
Browse files Browse the repository at this point in the history
…orn-52.0.0
  • Loading branch information
li-jia-nan committed Apr 19, 2024
2 parents 7244757 + ea267a6 commit 9f18bb1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-tabs",
"version": "14.1.1",
"version": "15.0.0",
"description": "tabs ui component for react",
"keywords": [
"react",
Expand Down Expand Up @@ -49,7 +49,7 @@
"@rc-component/father-plugin": "^1.0.0",
"@rc-component/trigger": "^2.0.0",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.2",
"@testing-library/react": "^15.0.2",
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.5",
"@types/jest": "^29.4.0",
Expand All @@ -61,7 +61,7 @@
"cross-env": "^7.0.2",
"dumi": "^2.0.0",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jest": "^28.2.0",
"eslint-plugin-unicorn": "^52.0.0",
"fastclick": "~1.0.6",
"father": "^4.0.0",
Expand Down
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

0 comments on commit 9f18bb1

Please sign in to comment.