Skip to content

Commit 9ac8ca2

Browse files
committed
chore(components/collapse-transition): 更新 demo
1 parent 8752ec5 commit 9ac8ca2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/components/src/collapse-transition/demo/fixed-width.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
*/
55

66
import { CollapseTransition, Divider, Button } from '@tool-pack/react-ui';
7-
import React, { useLayoutEffect, useState } from 'react';
7+
import React, { useLayoutEffect, useState, useRef } from 'react';
8+
89
const App: React.FC = () => {
910
const [visible, setVisible] = useState(true);
11+
const elRef = useRef<HTMLDivElement>(null);
12+
1013
useLayoutEffect(() => {
11-
// 该元素的ref已经被Transition组件获取了,无法再在外部靠useRef获取
12-
const el = document.querySelector<HTMLDivElement>(
13-
'#collapse-horizontal2-demo',
14-
);
14+
const el = elRef.current;
1515
if (!el) return;
1616

1717
const timer = setTimeout(() => {
@@ -21,14 +21,16 @@ const App: React.FC = () => {
2121

2222
return () => clearTimeout(timer);
2323
}, []);
24+
2425
return (
2526
<div>
2627
<div style={{ paddingBottom: '8px', textAlign: 'center' }}>
2728
<Button onClick={() => setVisible((v) => !v)}>toggle</Button>
2829
</div>
2930
<CollapseTransition show={visible} width>
3031
<div style={{ background: '#910852', color: 'white' }}>
31-
<div id="collapse-horizontal2-demo" style={{ padding: '10px' }}>
32+
{/* 下面这层 div 是为了固定宽度 */}
33+
<div style={{ padding: '10px' }} ref={elRef}>
3234
<p>
3335
载(zài)营魄抱一,能无离乎?专气致柔,能婴儿乎?涤除玄览,能无疵乎?爱民治国,能无知(zhì)乎?天门开阖(hé),能无雌乎?明白四达,能无为乎?生之、畜(xù)之,生而不有,为而不恃,长(zhǎng)而不宰,是谓玄德。
3436
</p>

0 commit comments

Comments
 (0)