diff --git a/README.md b/README.md index 2bbf9e03..221cd54a 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,6 @@ React.render( | activeKey | string | - | current active tabPanel's key | | animated | boolean \| { inkBar: boolean, tabPane: boolean } | `{ inkBar: true, tabPane: false }` | config animation | | defaultActiveKey | string | - | initial active tabPanel's key if activeKey is absent | -| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab | | direction | `'ltr' | 'rlt'` | `'ltr'` | Layout direction of tabs component | | editable | { onEdit(type: 'add' | 'remove', info: { key, event }), showAdd: boolean, removeIcon: ReactNode, addIcon: ReactNode } | - | config tab editable | | locale | { dropdownAriaLabel: string, removeAriaLabel: string, addAriaLabel: string } | - | Accessibility locale help text | @@ -100,6 +99,7 @@ React.render( | forceRender | boolean | false | forced render of content in tabs, not lazy render after clicking on tabs | | tab | ReactNode | - | current tab's title corresponding to current tabPane | | closeIcon | ReactNode | - | Config close icon | +| destroyInactiveTabPane | boolean | false | whether destroy inactive TabPane when change tab | ## Development diff --git a/docs/examples/mix.tsx b/docs/examples/mix.tsx index 79693c60..a903bfea 100644 --- a/docs/examples/mix.tsx +++ b/docs/examples/mix.tsx @@ -82,7 +82,17 @@ export default () => { setDestroyInactiveTabPane(val => !val)} + onChange={() => { + setTabPanes(tabs => + tabs.map(tab => + React.cloneElement(tab, { + ...tab.props, + destroyInactiveTabPane: !tab.props.destroyInactiveTabPane, + }), + ), + ); + setDestroyInactiveTabPane(val => !val); + }} /> Destroy Inactive TabPane @@ -150,7 +160,6 @@ export default () => { onTabScroll={info => { console.log('Scroll:', info); }} - destroyInactiveTabPane={destroyInactiveTabPane} animated={{ tabPane: animated }} editable={editableConfig} direction={rtl ? 'rtl' : null} diff --git a/src/TabPanelList/TabPane.tsx b/src/TabPanelList/TabPane.tsx index c21996ab..1346d14c 100644 --- a/src/TabPanelList/TabPane.tsx +++ b/src/TabPanelList/TabPane.tsx @@ -10,6 +10,7 @@ export interface TabPaneProps { forceRender?: boolean; closable?: boolean; closeIcon?: React.ReactNode; + destroyInactiveTabPane?: boolean; // Pass by TabPaneList prefixCls?: string; @@ -17,7 +18,6 @@ export interface TabPaneProps { id?: string; animated?: boolean; active?: boolean; - destroyInactiveTabPane?: boolean; } export default function TabPane({ diff --git a/src/TabPanelList/index.tsx b/src/TabPanelList/index.tsx index ac1d0a9d..06280a16 100644 --- a/src/TabPanelList/index.tsx +++ b/src/TabPanelList/index.tsx @@ -9,7 +9,6 @@ export interface TabPanelListProps { rtl: boolean; animated?: AnimatedConfig; tabPosition?: TabPosition; - destroyInactiveTabPane?: boolean; } export default function TabPanelList({ @@ -18,12 +17,11 @@ export default function TabPanelList({ animated, tabPosition, rtl, - destroyInactiveTabPane, }: TabPanelListProps) { const { prefixCls, tabs } = React.useContext(TabContext); const tabPaneAnimated = animated.tabPane; - const activeIndex = tabs.findIndex(tab => tab.key === activeKey); + const activeIndex = tabs.findIndex((tab) => tab.key === activeKey); return (