Skip to content

Commit 62e65d9

Browse files
committed
🌟 support extra for Collapse.Panel
close #11626
1 parent 5ad9469 commit 62e65d9

File tree

7 files changed

+100
-1
lines changed

7 files changed

+100
-1
lines changed

components/collapse/Collapse.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface PanelProps {
2828
showArrow?: boolean;
2929
forceRender?: boolean;
3030
disabled?: boolean;
31+
extra?: React.ReactNode;
3132
}
3233

3334
export default class Collapse extends React.Component<CollapseProps, any> {

components/collapse/CollapsePanel.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface CollapsePanelProps {
1313
prefixCls?: string;
1414
forceRender?: boolean;
1515
id?: string;
16+
extra?: React.ReactNode;
1617
}
1718

1819
export default class CollapsePanel extends React.Component<CollapsePanelProps, {}> {

components/collapse/__tests__/__snapshots__/index.test.js.snap

+85
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,90 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Collapse should render extra node of panel 1`] = `
4+
<div
5+
class="ant-collapse"
6+
>
7+
<div
8+
class="ant-collapse-item"
9+
>
10+
<div
11+
aria-expanded="false"
12+
class="ant-collapse-header"
13+
role="button"
14+
tabindex="0"
15+
>
16+
<i
17+
aria-label="icon: right"
18+
class="anticon anticon-right ant-collapse-arrow"
19+
>
20+
<svg
21+
aria-hidden="true"
22+
class=""
23+
data-icon="right"
24+
fill="currentColor"
25+
height="1em"
26+
viewBox="64 64 896 896"
27+
width="1em"
28+
>
29+
<path
30+
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"
31+
/>
32+
</svg>
33+
</i>
34+
header
35+
<div
36+
class="ant-collapse-extra"
37+
>
38+
<button
39+
type="button"
40+
>
41+
action
42+
</button>
43+
</div>
44+
</div>
45+
</div>
46+
<div
47+
class="ant-collapse-item"
48+
>
49+
<div
50+
aria-expanded="false"
51+
class="ant-collapse-header"
52+
role="button"
53+
tabindex="0"
54+
>
55+
<i
56+
aria-label="icon: right"
57+
class="anticon anticon-right ant-collapse-arrow"
58+
>
59+
<svg
60+
aria-hidden="true"
61+
class=""
62+
data-icon="right"
63+
fill="currentColor"
64+
height="1em"
65+
viewBox="64 64 896 896"
66+
width="1em"
67+
>
68+
<path
69+
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"
70+
/>
71+
</svg>
72+
</i>
73+
header
74+
<div
75+
class="ant-collapse-extra"
76+
>
77+
<button
78+
type="button"
79+
>
80+
action
81+
</button>
82+
</div>
83+
</div>
84+
</div>
85+
</div>
86+
`;
87+
388
exports[`Collapse should support remove expandIcon 1`] = `
489
<div
590
class="ant-collapse"

components/collapse/__tests__/index.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ describe('Collapse', () => {
1111
);
1212
expect(wrapper.render()).toMatchSnapshot();
1313
});
14+
15+
it('should render extra node of panel', () => {
16+
const wrapper = mount(
17+
<Collapse>
18+
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
19+
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
20+
</Collapse>
21+
);
22+
expect(wrapper.render()).toMatchSnapshot();
23+
});
1424
});

components/collapse/index.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ A content area which can be collapsed and expanded.
3535
| header | Title of the panel | string\|ReactNode | - |
3636
| key | Unique key identifying the panel from among its siblings | string | - |
3737
| showArrow | If `false`, panel will not show arrow icon | boolean | `true` |
38+
| extra | extra element in the corner | ReactNode | - |
3839

3940
## FAQ
4041

components/collapse/index.zh-CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ cols: 1
3636
| header | 面板头内容 | string\|ReactNode ||
3737
| key | 对应 activeKey | string ||
3838
| showArrow | 是否展示当前面板上的箭头 | boolean | `true` |
39+
| extra | 自定义渲染每个面板右上角的内容 | ReactNode | - |
3940

4041
## FAQ
4142

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"rc-calendar": "~9.10.3",
5959
"rc-cascader": "~0.17.0",
6060
"rc-checkbox": "~2.1.5",
61-
"rc-collapse": "~1.10.2",
61+
"rc-collapse": "~1.11.1",
6262
"rc-dialog": "~7.3.0",
6363
"rc-drawer": "~1.7.6",
6464
"rc-dropdown": "~2.4.1",

0 commit comments

Comments
 (0)