-
-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathTabPane.tsx
More file actions
74 lines (68 loc) · 1.6 KB
/
TabPane.tsx
File metadata and controls
74 lines (68 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as React from 'react';
import classNames from 'classnames';
export interface TabPaneProps {
tab?: React.ReactNode;
menuTab?: React.ReactNode;
className?: string;
style?: React.CSSProperties;
disabled?: boolean;
children?: React.ReactNode;
forceRender?: boolean;
closable?: boolean;
closeIcon?: React.ReactNode;
// Pass by TabPaneList
prefixCls?: string;
tabKey?: string;
id?: string;
animated?: boolean;
active?: boolean;
destroyInactiveTabPane?: boolean;
}
export default function TabPane({
prefixCls,
forceRender,
className,
style,
id,
active,
animated,
destroyInactiveTabPane,
tabKey,
children,
}: TabPaneProps) {
const [visited, setVisited] = React.useState(forceRender);
React.useEffect(() => {
if (active) {
setVisited(true);
} else if (destroyInactiveTabPane) {
setVisited(false);
}
}, [active, destroyInactiveTabPane]);
const mergedStyle: React.CSSProperties = {};
if (!active) {
if (animated) {
mergedStyle.visibility = 'hidden';
mergedStyle.height = 0;
mergedStyle.overflowY = 'hidden';
} else {
mergedStyle.display = 'none';
}
}
return (
<div
id={id && `${id}-panel-${tabKey}`}
role="tabpanel"
tabIndex={active ? 0 : -1}
aria-labelledby={id && `${id}-tab-${tabKey}`}
aria-hidden={!active}
style={{ ...mergedStyle, ...style }}
className={classNames(
`${prefixCls}-tabpane`,
active && `${prefixCls}-tabpane-active`,
className,
)}
>
{(active || visited || forceRender) && children}
</div>
);
}