Skip to content

Commit 345e6f7

Browse files
committedNov 9, 2023
style(Collapse): fix Panel height issue. (#974)
1 parent 1808de3 commit 345e6f7

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed
 

Diff for: ‎packages/react-collapse/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,63 @@ import { Collapse } from 'uiw';
1313
import Collapse from '@uiw/react-collapse';
1414
```
1515

16+
```jsx mdx:preview&bg=#fff
17+
import React, { useState } from 'react';
18+
import { Collapse } from 'uiw';
19+
20+
const styl = {
21+
border: '1px solid #efefef',
22+
marginBottom: 10,
23+
//height: 32,
24+
//lineHeight: 32,
25+
padding: 10,
26+
}
27+
28+
export default function App() {
29+
const [recent, setRecent] = useState([]);
30+
const [list, setList] = useState(["a", "b", "c", "d", "e"]);
31+
const onListClick = (index) => {
32+
const newList = [...list];
33+
const ls = newList.splice(index, 1);
34+
setRecent([...recent, ls]);
35+
setList(newList);
36+
};
37+
const onRecentClick = (index) => {
38+
const newRecent = [...recent];
39+
const ls = newRecent.splice(index, 1);
40+
setList([...list, ls]);
41+
setRecent(newRecent);
42+
};
43+
return (
44+
<div className="App">
45+
{/* <Scrollbars autoHide> */}
46+
<Collapse>
47+
<Collapse.Panel header="Test1">
48+
{recent.map((item) => {
49+
return (
50+
<div className="item" style={styl} key={item} onClick={onRecentClick}>
51+
{item}
52+
</div>
53+
);
54+
})}
55+
</Collapse.Panel>
56+
<Collapse.Panel header="Tset2">
57+
{list.map((item) => {
58+
return (
59+
<div className="item" key={item} style={styl} onClick={onListClick}>
60+
{item}
61+
</div>
62+
);
63+
})}
64+
</Collapse.Panel>
65+
</Collapse>
66+
{/* </Scrollbars> */}
67+
</div>
68+
);
69+
}
70+
71+
72+
```
1673
## 基本用法
1774

1875
可以同时展开多个面板,这个例子默认展开了第一个。

Diff for: ‎packages/react-collapse/src/Panel.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ function getElementHeight(elm: HTMLDivElement) {
9797
const computedStyle = getComputedStyle(childNode);
9898
const height =
9999
childNode.offsetHeight +
100-
parseInt(computedStyle.marginTop) +
100+
+parseInt(computedStyle.marginTop) +
101101
parseInt(computedStyle.marginBottom) +
102102
parseInt(computedStyle.borderTopWidth) +
103-
parseInt(computedStyle.borderBottomWidth) +
104-
parseInt(computedStyle.paddingTop) +
105-
parseInt(computedStyle.paddingBottom);
103+
parseInt(computedStyle.borderBottomWidth);
106104
totalHeight += height;
107105

108106
const beforeStyle = getComputedStyle(childNode, '::before');

1 commit comments

Comments
 (1)

jaywcjlove commented on Nov 9, 2023

@jaywcjlove
MemberAuthor
Please sign in to comment.