{tabNavBar}
+
;
export type TabPosition = 'left' | 'right' | 'top' | 'bottom';
-export interface Tab extends TabPaneProps {
+export interface Tab extends Omit {
key: string;
- node: React.ReactElement;
+ label: React.ReactNode;
}
type RenderTabBarProps = {
@@ -38,6 +39,7 @@ type RenderTabBarProps = {
onTabScroll: OnTabScroll;
extra: TabBarExtraContent;
style: React.CSSProperties;
+ /** @deprecated It do not pass real TabPane node. Only for compatible usage. */
panes: React.ReactNode;
};
@@ -55,7 +57,7 @@ export interface TabsLocale {
export interface EditableConfig {
onEdit: (
type: 'add' | 'remove',
- info: { key?: string; event: React.MouseEvent | React.KeyboardEvent },
+ info: { key?: React.Key; event: React.MouseEvent | React.KeyboardEvent },
) => void;
showAdd?: boolean;
removeIcon?: React.ReactNode;
diff --git a/tests/common/util.tsx b/tests/common/util.tsx
index 104158fa..3dda597c 100644
--- a/tests/common/util.tsx
+++ b/tests/common/util.tsx
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-invalid-this */
import React from 'react';
import type { ReactWrapper } from 'enzyme';
-import Tabs, { TabPane } from '../../src';
+import Tabs from '../../src';
import type { TabsProps } from '../../src/Tabs';
export function getOffsetSizeFunc(
@@ -65,23 +65,37 @@ export function getTransformY(wrapper: ReactWrapper) {
export function getTabs(props: TabsProps = null) {
return (
-
-
- Light
-
-
- Bamboo
-
-
- Cute
-
-
- Disabled
-
-
- Miu
-
-
+
);
}
diff --git a/tests/index.test.tsx b/tests/index.test.tsx
index 8f70fb20..042bfcc0 100644
--- a/tests/index.test.tsx
+++ b/tests/index.test.tsx
@@ -2,22 +2,28 @@ import React from 'react';
import type { ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
-import Tabs, { TabPane } from '../src';
+import Tabs from '../src';
import type { TabsProps } from '../src/Tabs';
describe('Tabs.Basic', () => {
function getTabs(props: TabsProps = null) {
const mergedProps = {
- children: [
-
- Light
- ,
-
- Bamboo
- ,
-
- Cute
- ,
+ items: [
+ {
+ label: 'light',
+ key: 'light',
+ children: 'Light',
+ },
+ {
+ label: 'bamboo',
+ key: 'bamboo',
+ children: 'Bamboo',
+ },
+ {
+ label: 'cute',
+ key: 'cute',
+ children: 'Cute',
+ },
],
...props,
};
@@ -31,14 +37,42 @@ describe('Tabs.Basic', () => {
expect(wrapper.render()).toMatchSnapshot();
});
+ it('disabled not change', () => {
+ const onChange = jest.fn();
+
+ const wrapper = mount(
+ getTabs({
+ defaultActiveKey: 'light',
+ items: [
+ {
+ label: 'light',
+ key: 'light',
+ children: 'Light',
+ },
+ {
+ label: 'disabled',
+ key: 'disabled',
+ children: 'Disabled',
+ disabled: true,
+ },
+ ],
+ }),
+ );
+
+ wrapper.find('.rc-tabs-tab-disabled').simulate('click');
+ expect(onChange).not.toHaveBeenCalled();
+ });
+
it('Skip invalidate children', () => {
const wrapper = mount(
getTabs({
- children: [
-
- Light
- ,
- 'not me',
+ items: [
+ {
+ label: 'light',
+ key: 'light',
+ children: 'Light',
+ },
+ 'not me' as any,
],
}),
);
@@ -48,7 +82,7 @@ describe('Tabs.Basic', () => {
});
it('nothing for empty tabs', () => {
- mount(getTabs({ children: null }));
+ mount(getTabs({ items: null }));
});
describe('onChange and onTabClick should work', () => {
@@ -97,11 +131,13 @@ describe('Tabs.Basic', () => {
it('active first tab when children is changed', () => {
const wrapper = mount(getTabs());
wrapper.setProps({
- children: (
-
- New
-
- ),
+ items: [
+ {
+ label: 'Yo',
+ key: '2333',
+ children: 'New',
+ },
+ ],
});
wrapper.update();
expect(wrapper.find('.rc-tabs-tab-active').text()).toEqual('Yo');
@@ -112,11 +148,13 @@ describe('Tabs.Basic', () => {
expect(wrapper.find('.rc-tabs-tab-active').text()).toEqual('light');
wrapper.setProps({
- children: (
-
- New
-
- ),
+ items: [
+ {
+ label: 'Yo',
+ key: '2333',
+ children: 'New',
+ },
+ ],
});
expect(wrapper.find('.rc-tabs-tab-active')).toHaveLength(0);
});
@@ -169,7 +207,16 @@ describe('Tabs.Basic', () => {
getTabs({
activeKey: 'light',
destroyInactiveTabPane: true,
- children: [Light, Bamboo],
+ items: [
+ {
+ key: 'light',
+ children: 'Light',
+ },
+ {
+ key: 'bamboo',
+ children: 'Bamboo',
+ },
+ ] as any,
}),
);
@@ -233,11 +280,13 @@ describe('Tabs.Basic', () => {
const wrapper = mount(
getTabs({
editable: { onEdit },
- children: [
- }>
- Light
- ,
- ],
+ items: [
+ {
+ key: 'light',
+ closeIcon: ,
+ children: 'Light',
+ },
+ ] as any,
}),
);
diff --git a/tests/mobile.test.tsx b/tests/mobile.test.tsx
index 4fbe21c2..1bbe4eb4 100644
--- a/tests/mobile.test.tsx
+++ b/tests/mobile.test.tsx
@@ -1,9 +1,10 @@
import React from 'react';
-import { mount, ReactWrapper } from 'enzyme';
+import { mount } from 'enzyme';
+import type { ReactWrapper } from 'enzyme';
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
import { act } from 'react-dom/test-utils';
-import Tabs, { TabPane } from '../src';
-import { TabsProps } from '../src/Tabs';
+import Tabs from '../src';
+import type { TabsProps } from '../src';
import { getTransformX } from './common/util';
describe('Tabs.Mobile', () => {
@@ -25,16 +26,16 @@ describe('Tabs.Mobile', () => {
const tabCount = 100;
function getTabs(props: TabsProps = null) {
- const children: React.ReactElement[] = [];
+ const items: TabsProps['items'] = [];
for (let i = 0; i < tabCount; i += 1) {
- children.push(
-
- {i}
- ,
- );
+ items.push({
+ label: i,
+ key: String(i),
+ children: i,
+ });
}
- return {children};
+ return ;
}
describe('mobile is scrollable', () => {
@@ -55,7 +56,7 @@ describe('Tabs.Mobile', () => {
get() {
// Mock button offset
const btn = this as HTMLButtonElement;
- const btnList = [...btn.parentNode.childNodes].filter(ele =>
+ const btnList = Array.from(btn.parentNode.childNodes).filter(ele =>
(ele as HTMLElement).className.includes('rc-tabs-tab'),
);
const index = btnList.indexOf(btn);
@@ -101,7 +102,7 @@ describe('Tabs.Mobile', () => {
});
// Touch to move
- const node = (wrapper.find('.rc-tabs-nav-wrap').instance() as unknown) as HTMLElement;
+ const node = wrapper.find('.rc-tabs-nav-wrap').instance() as unknown as HTMLElement;
act(() => {
const touchStart = new TouchEvent('touchstart', {
diff --git a/tests/operation-overflow.test.tsx b/tests/operation-overflow.test.tsx
index aac79540..dd347d5d 100644
--- a/tests/operation-overflow.test.tsx
+++ b/tests/operation-overflow.test.tsx
@@ -15,7 +15,7 @@ describe('Tabs.Operation-Overflow', () => {
function btnOffsetPosition() {
const btn = this as HTMLButtonElement;
- const btnList = [...btn.parentNode.childNodes].filter(ele =>
+ const btnList = Array.from(btn.parentNode.childNodes).filter(ele =>
(ele as HTMLElement).className.includes('rc-tabs-tab'),
);
const index = btnList.indexOf(btn);
diff --git a/tests/overflow.test.tsx b/tests/overflow.test.tsx
index af322dcb..94491826 100644
--- a/tests/overflow.test.tsx
+++ b/tests/overflow.test.tsx
@@ -10,7 +10,8 @@ import {
getTransformY,
triggerResize,
} from './common/util';
-import Tabs, { TabPane } from '../src';
+import type { TabsProps } from '../src';
+import Tabs from '../src';
describe('Tabs.Overflow', () => {
let domSpy: ReturnType;
@@ -209,7 +210,17 @@ describe('Tabs.Overflow', () => {
hackOffsetInfo.list = 20;
jest.useFakeTimers();
- const wrapper = mount(getTabs({ children: [Yo], tabPosition }));
+ const wrapper = mount(
+ getTabs({
+ items: [
+ {
+ key: 'yo',
+ children: 'Yo',
+ } as any,
+ ],
+ tabPosition,
+ }),
+ );
triggerResize(wrapper);
act(() => {
@@ -358,31 +369,28 @@ describe('Tabs.Overflow', () => {
console.log('run here');
jest.useFakeTimers();
- let children = new Array(8).fill(0).map((_, index) => {
- return (
-
- {`Tab Content${index + 1}`}
-
- );
- });
+ let items: TabsProps['items'] = new Array(8).fill(0).map((_, index) => ({
+ key: `${index}`,
+ label: `Tab ${index + 1}`,
+ children: `Tab Content${index + 1}`,
+ }));
const wrapper = mount(
{
+ items = items.filter(ele => {
return ele.key !== key.toString();
});
wrapper.setProps({
- children,
+ items,
});
}
},
}}
- >
- {children}
- ,
+ items={items}
+ />,
);
triggerResize(wrapper);
@@ -437,7 +445,7 @@ describe('Tabs.Overflow', () => {
it('should support getPopupContainer', () => {
const getPopupContainer = trigger => trigger.parentNode;
const wrapper = mount(getTabs({ getPopupContainer }));
- expect(wrapper.find('Trigger').first().props().getPopupContainer).toBe(getPopupContainer);
+ expect(wrapper.find('Trigger').first().prop('getPopupContainer')).toBe(getPopupContainer);
});
it('should support popupClassName', () => {
diff --git a/tests/rtl.test.tsx b/tests/rtl.test.tsx
index 614400ba..83b9a378 100644
--- a/tests/rtl.test.tsx
+++ b/tests/rtl.test.tsx
@@ -28,7 +28,7 @@ describe('Tabs.RTL', () => {
get() {
// Mock button offset
const btn = this as HTMLButtonElement;
- const btnList = [...btn.parentNode.childNodes].filter(ele =>
+ const btnList = Array.from(btn.parentNode.childNodes).filter(ele =>
(ele as HTMLElement).className.includes('rc-tabs-tab'),
);
const index = btnList.indexOf(btn);