@huibo-ui/react-antd 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Tabs.d.ts +2 -0
- package/lib/components/Tabs.js +18 -1
- package/package.json +1 -1
package/lib/components/Tabs.d.ts
CHANGED
package/lib/components/Tabs.js
CHANGED
|
@@ -50,10 +50,27 @@ export function Tabs(props) {
|
|
|
50
50
|
background: PRIMARY,
|
|
51
51
|
} }))] }, it.key));
|
|
52
52
|
}) }));
|
|
53
|
+
// 对齐 antd Tabs 默认的渲染策略:
|
|
54
|
+
// - destroyInactiveTabPane=true:只渲染当前 active(切换即销毁旧的)
|
|
55
|
+
// - 默认(lazy keep-alive):只渲染「当前 active」和「曾经 active 过」的;
|
|
56
|
+
// 从未激活过的 tab 不渲染 children(避免其内部副作用/接口被提前触发)。
|
|
57
|
+
// forceRender=true 的 tab 始终渲染。
|
|
58
|
+
const visitedRef = React.useRef(new Set());
|
|
59
|
+
if (current)
|
|
60
|
+
visitedRef.current.add(current);
|
|
61
|
+
// activeKey 受控切换时清理已销毁的 key(避免 Set 无限增长)
|
|
62
|
+
const validKeys = new Set(list.map(it => it.key));
|
|
63
|
+
visitedRef.current = new Set([...visitedRef.current].filter(k => validKeys.has(k)));
|
|
53
64
|
const activeItem = list.find(it => it.key === current);
|
|
54
65
|
const panels = (_jsxs("div", { style: { flex: 1, minWidth: 0, padding: vertical ? '0 16px' : '16px 0' }, children: [destroyInactiveTabPane
|
|
55
66
|
? activeItem?.children
|
|
56
|
-
: list.map(it =>
|
|
67
|
+
: list.map(it => {
|
|
68
|
+
const visited = visitedRef.current.has(it.key);
|
|
69
|
+
const shouldRender = it.forceRender || visited;
|
|
70
|
+
if (!shouldRender)
|
|
71
|
+
return _jsx("div", { style: { display: 'none' } }, it.key);
|
|
72
|
+
return (_jsx("div", { style: { display: it.key === current ? 'block' : 'none' }, children: it.children }, it.key));
|
|
73
|
+
}), !items || items.length === 0 ? children : null] }));
|
|
57
74
|
return (_jsxs("div", { className: className, style: {
|
|
58
75
|
display: 'flex',
|
|
59
76
|
flexDirection: vertical ? 'row' : 'column',
|