@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.
@@ -12,6 +12,8 @@ export interface TabItemType {
12
12
  label?: React.ReactNode;
13
13
  children?: React.ReactNode;
14
14
  disabled?: boolean;
15
+ /** 强制预渲染(即使非 active 也渲染)。对齐 antd forceRender,默认 false。 */
16
+ forceRender?: boolean;
15
17
  [k: string]: any;
16
18
  }
17
19
  export interface TabsProps {
@@ -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 => (_jsx("div", { style: { display: it.key === current ? 'block' : 'none' }, children: it.children }, it.key))), !items || items.length === 0 ? children : null] }));
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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huibo-ui/react-antd",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "antd 兼容层 — 接收 antd 原生 props,内部转换为 huibo-ui,实现丝滑平替",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",