Skip to content

Commit

Permalink
fix: (Tabs & CapsuleTabs & JumboTabs) wrap pane content with ShouldRe…
Browse files Browse the repository at this point in the history
…nder
  • Loading branch information
awmleer committed Feb 28, 2022
1 parent db89e14 commit 5a9d665
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
27 changes: 14 additions & 13 deletions src/components/capsule-tabs/capsule-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { usePropsValue } from '../../utils/use-props-value'
import { useResizeEffect } from '../../utils/use-resize-effect'
import { useTabListScroll } from '../../utils/use-tab-list-scroll'
import ScrollMask from '../scroll-mask'
import { ShouldRender } from '../../utils/should-render'

const classPrefix = `adm-capsule-tabs`

Expand Down Expand Up @@ -107,21 +108,21 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
if (pane.props.children === undefined) {
return null
}
if (pane.key === activeKey) {
return (
<div key={pane.key} className={`${classPrefix}-content`}>
const active = pane.key === activeKey
return (
<ShouldRender
key={pane.key}
active={active}
forceRender={pane.props.forceRender}
>
<div
className={`${classPrefix}-content`}
style={{ display: active ? 'block' : 'none' }}
>
{pane.props.children}
</div>
)
}
if (pane.props.forceRender) {
return (
<div key={pane.key} style={{ display: 'none' }}>
{pane.props.children}
</div>
)
}
return null
</ShouldRender>
)
})}
</div>
)
Expand Down
27 changes: 14 additions & 13 deletions src/components/jumbo-tabs/jumbo-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { usePropsValue } from '../../utils/use-props-value'
import { useResizeEffect } from '../../utils/use-resize-effect'
import { useTabListScroll } from '../../utils/use-tab-list-scroll'
import ScrollMask from '../scroll-mask'
import { ShouldRender } from '../../utils/should-render'

const classPrefix = `adm-jumbo-tabs`

Expand Down Expand Up @@ -113,21 +114,21 @@ export const JumboTabs: FC<JumboTabsProps> = props => {
if (pane.props.children === undefined) {
return null
}
if (pane.key === activeKey) {
return (
<div key={pane.key} className={`${classPrefix}-content`}>
const active = pane.key === activeKey
return (
<ShouldRender
key={pane.key}
active={active}
forceRender={pane.props.forceRender}
>
<div
className={`${classPrefix}-content`}
style={{ display: active ? 'block' : 'none' }}
>
{pane.props.children}
</div>
)
}
if (pane.props.forceRender) {
return (
<div key={pane.key} style={{ display: 'none' }}>
{pane.props.children}
</div>
)
}
return null
</ShouldRender>
)
})}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/demos/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Tabs, Badge } from 'antd-mobile'
import { Tabs } from 'antd-mobile'
import { DemoBlock } from 'demos'

export default () => {
Expand Down
25 changes: 11 additions & 14 deletions src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useMutationEffect } from '../../utils/use-mutation-effect'
import { useResizeEffect } from '../../utils/use-resize-effect'
import { mergeProps } from '../../utils/with-default-props'
import { useIsomorphicUpdateLayoutEffect } from '../../utils/use-isomorphic-update-layout-effect'
import { ShouldRender } from '../../utils/should-render'

const classPrefix = `adm-tabs`

Expand Down Expand Up @@ -288,25 +289,21 @@ export const Tabs: FC<TabsProps> = p => {
if (pane.props.children === undefined) {
return null
}
if (pane.key === activeKey) {
return (
<div key={pane.key} className={`${classPrefix}-content`}>
{pane.props.children}
</div>
)
}
if (pane.props.forceRender) {
return (
const active = pane.key === activeKey
return (
<ShouldRender
key={pane.key}
active={active}
forceRender={pane.props.forceRender}
>
<div
key={pane.key}
className={`${classPrefix}-content`}
style={{ display: 'none' }}
style={{ display: active ? 'block' : 'none' }}
>
{pane.props.children}
</div>
)
}
return null
</ShouldRender>
)
})}
</div>
)
Expand Down

0 comments on commit 5a9d665

Please sign in to comment.