Skip to content

Commit a546f31

Browse files
authored
chore: rename destroyInactiveTabPane => destroyOnHidden (#830)
* chore: rename destroyInactiveTabPane => destroyOnClose * fix: fix
1 parent 2b3ecab commit a546f31

File tree

6 files changed

+24
-37
lines changed

6 files changed

+24
-37
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ React Tabs component.
1717
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-tabs
1818
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-tabs
1919

20-
2120
## Screenshot
2221

2322
<img src='https://zos.alipayobjects.com/rmsportal/JwLASrsOYJuFRIt.png' width='408'>
@@ -45,7 +44,7 @@ online example: https://tabs.react-component.now.sh/
4544
import Tabs from 'rc-tabs';
4645
import ReactDom from 'react-dom';
4746

48-
const callback = (key) => {
47+
const callback = key => {
4948
console.log(key);
5049
};
5150

@@ -112,7 +111,7 @@ ReactDom.render(
112111
| tabBarPosition | `'left' \| 'right' \| 'top' \| 'bottom'` | `'top'` | tab nav 's position |
113112
| tabBarStyle | style | - | tab nav style |
114113
| tabPosition | `'left' or 'right' or 'top' or 'bottom'` | `'top'` | tab nav 's position |
115-
| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab |
114+
| destroyOnHidden | boolean | false | whether destroy inactive TabPane when change tab |
116115
| onChange | (key) => void | - | called when tabPanel is changed |
117116
| onTabClick | (key) => void | - | called when tab click |
118117
| onTabScroll | ({ direction }) => void | - | called when tab scroll |
@@ -137,16 +136,15 @@ ReactDom.render(
137136
| prefixCls | string | `'rc-tabs-tab'` | prefix class name, use to custom style |
138137
| id | string | - | unique identifier |
139138
| animated | boolean \| { inkBar: boolean, tabPane: boolean } | `{ inkBar: true, tabPane: false }` | config animation |
140-
| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab |
139+
| destroyOnHidden | boolean | false | whether destroy inactive TabPane when change tab |
141140
| active | boolean | false | active feature of tab item |
142141
| tabKey | string | - | key linked to tab |
143142

144-
145143
### TabPane(support in older versions)
146144

147145
| name | type | default | description |
148146
| --- | --- | --- | --- |
149-
| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab |
147+
| destroyOnHidden | boolean | false | whether destroy inactive TabPane when change tab |
150148
| key | string | - | corresponding to activeKey, should be unique |
151149
| forceRender | boolean | false | forced render of content in tabs, not lazy render after clicking on tabs |
152150
| tab | ReactNode | - | current tab's title corresponding to current tabPane |
@@ -182,10 +180,6 @@ rc-tabs is released under the MIT license.
182180

183181
### Responsive Tabs
184182

185-
There are 3 cases when handling responsive tabs:
186-
![image](https://user-images.githubusercontent.com/27722486/156315099-7e6eda9d-ab77-4b16-9b49-1727c5ec8b26.png)
183+
There are 3 cases when handling responsive tabs: ![image](https://user-images.githubusercontent.com/27722486/156315099-7e6eda9d-ab77-4b16-9b49-1727c5ec8b26.png)
187184

188-
We get hidden tabs through [useVisibleRange.ts](https://github.com/react-component/tabs/blob/master/src/hooks/useVisibleRange.ts).
189-
If enconter the third case, in order to make tabs responsive, some tabs should be hidden.
190-
So we minus `addSize` when calculating `basicSize` manully, even though there's no addNode in container.
191-
In this way, case 3 turns to case 2, tabs become stable again.
185+
We get hidden tabs through [useVisibleRange.ts](https://github.com/react-component/tabs/blob/master/src/hooks/useVisibleRange.ts). If enconter the third case, in order to make tabs responsive, some tabs should be hidden. So we minus `addSize` when calculating `basicSize` manully, even though there's no addNode in container. In this way, case 3 turns to case 2, tabs become stable again.

docs/examples/mix.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default () => {
2424
const [fixHeight, setFixHeight] = React.useState(true);
2525
const [rtl, setRTL] = React.useState(false);
2626
const [editable, setEditable] = React.useState(true);
27-
const [destroyInactiveTabPane, setDestroyInactiveTabPane] = React.useState(false);
27+
const [destroyOnHidden, setDestroyOnHidden] = React.useState(false);
2828
const [destroy, setDestroy] = React.useState(false);
2929
const [animated, setAnimated] = React.useState(true);
3030
const [tabPanes, setTabPanes] = React.useState(getTabPanes(10));
@@ -86,8 +86,8 @@ export default () => {
8686
<label>
8787
<input
8888
type="checkbox"
89-
checked={destroyInactiveTabPane}
90-
onChange={() => setDestroyInactiveTabPane(val => !val)}
89+
checked={destroyOnHidden}
90+
onChange={() => setDestroyOnHidden(val => !val)}
9191
/>
9292
Destroy Inactive TabPane
9393
</label>
@@ -155,7 +155,7 @@ export default () => {
155155
onTabScroll={info => {
156156
console.log('Scroll:', info);
157157
}}
158-
destroyInactiveTabPane={destroyInactiveTabPane}
158+
destroyOnHidden={destroyOnHidden}
159159
animated={{ tabPane: animated }}
160160
editable={editableConfig}
161161
direction={rtl ? 'rtl' : null}

src/TabPanelList/TabPane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface TabPaneProps {
1818
id?: string;
1919
animated?: boolean;
2020
active?: boolean;
21-
destroyInactiveTabPane?: boolean;
21+
destroyOnHidden?: boolean;
2222
}
2323

2424
const TabPane = React.forwardRef<HTMLDivElement, TabPaneProps>((props, ref) => {

src/TabPanelList/index.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,14 @@ export interface TabPanelListProps {
1010
id: string;
1111
animated?: AnimatedConfig;
1212
tabPosition?: TabPosition;
13-
destroyInactiveTabPane?: boolean;
13+
destroyOnHidden?: boolean;
1414
contentStyle?: React.CSSProperties;
1515
contentClassName?: string;
1616
}
1717

1818
const TabPanelList: React.FC<TabPanelListProps> = props => {
19-
const {
20-
id,
21-
activeKey,
22-
animated,
23-
tabPosition,
24-
destroyInactiveTabPane,
25-
contentStyle,
26-
contentClassName,
27-
} = props;
19+
const { id, activeKey, animated, tabPosition, destroyOnHidden, contentStyle, contentClassName } =
20+
props;
2821
const { prefixCls, tabs } = React.useContext(TabContext);
2922
const tabPaneAnimated = animated.tabPane;
3023

@@ -43,7 +36,7 @@ const TabPanelList: React.FC<TabPanelListProps> = props => {
4336
forceRender,
4437
style: paneStyle,
4538
className: paneClassName,
46-
destroyInactiveTabPane: itemDestroyInactiveTabPane,
39+
destroyOnHidden: itemDestroyOnHidden,
4740
...restTabProps
4841
} = item;
4942
const active = key === activeKey;
@@ -52,7 +45,7 @@ const TabPanelList: React.FC<TabPanelListProps> = props => {
5245
key={key}
5346
visible={active}
5447
forceRender={forceRender}
55-
removeOnLeave={!!(destroyInactiveTabPane || itemDestroyInactiveTabPane)}
48+
removeOnLeave={!!(destroyOnHidden ?? itemDestroyOnHidden)}
5649
leavedClassName={`${tabPanePrefixCls}-hidden`}
5750
{...animated.tabPaneMotion}
5851
>

src/Tabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface TabsProps
5656
tabBarGutter?: number;
5757
tabBarStyle?: React.CSSProperties;
5858
tabPosition?: TabPosition;
59-
destroyInactiveTabPane?: boolean;
59+
destroyOnHidden?: boolean;
6060

6161
onChange?: (activeKey: string) => void;
6262
onTabClick?: (activeKey: string, e: React.KeyboardEvent | React.MouseEvent) => void;
@@ -95,7 +95,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
9595
tabBarExtraContent,
9696
locale,
9797
more,
98-
destroyInactiveTabPane,
98+
destroyOnHidden,
9999
renderTabBar,
100100
onChange,
101101
onTabClick,
@@ -210,7 +210,7 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
210210
>
211211
<TabNavListWrapper {...tabNavBarProps} renderTabBar={renderTabBar} />
212212
<TabPanelList
213-
destroyInactiveTabPane={destroyInactiveTabPane}
213+
destroyOnHidden={destroyOnHidden}
214214
{...sharedProps}
215215
contentStyle={styles?.content}
216216
contentClassName={tabsClassNames?.content}

tests/index.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ describe('Tabs.Basic', () => {
312312
});
313313
});
314314

315-
it('destroyInactiveTabPane', () => {
315+
it('destroyOnHidden', () => {
316316
const props = {
317317
activeKey: 'light',
318-
destroyInactiveTabPane: true,
318+
destroyOnHidden: true,
319319
items: [
320320
{
321321
key: 'light',
@@ -346,20 +346,20 @@ describe('Tabs.Basic', () => {
346346
matchText('Bamboo');
347347
});
348348

349-
it('destroyInactiveTabPane from TabPane', () => {
349+
it('destroyOnHidden from TabPane', () => {
350350
const props = {
351351
activeKey: 'light',
352352

353353
items: [
354354
{
355355
key: 'light',
356356
children: 'Light',
357-
destroyInactiveTabPane: true,
357+
destroyOnHidden: true,
358358
},
359359
{
360360
key: 'bamboo',
361361
children: 'Bamboo',
362-
destroyInactiveTabPane: true,
362+
destroyOnHidden: true,
363363
},
364364
] as any,
365365
};

0 commit comments

Comments
 (0)