fix(collapse): the items type should be optional (#42877)

* fix(collapse): the items type should be optional

* test: add collapse panel usage
This commit is contained in:
Dunqing 2023-06-07 10:53:40 +08:00 committed by GitHub
parent 0afe8baf1e
commit 5ef315ba3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 2 deletions

View File

@ -20,8 +20,7 @@ import useStyle from './style';
type ExpandIconPositionLegacy = 'left' | 'right';
export type ExpandIconPosition = 'start' | 'end' | ExpandIconPositionLegacy | undefined;
export interface CollapseProps {
items: RcCollapseProps['items'];
export interface CollapseProps extends Pick<RcCollapseProps, 'items'> {
activeKey?: Array<string | number> | string | number;
defaultActiveKey?: Array<string | number> | string | number;
/** 手风琴效果 */

View File

@ -1,5 +1,92 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Collapse Collapse.Panel usage 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start ant-collapse-borderless"
>
<div
class="ant-collapse-item"
>
<div
aria-disabled="false"
aria-expanded="false"
class="ant-collapse-header"
role="button"
tabindex="0"
>
<div
class="ant-collapse-expand-icon"
>
<span
aria-label="right"
class="anticon anticon-right ant-collapse-arrow"
role="img"
>
<svg
aria-hidden="true"
data-icon="right"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 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 000-50.4z"
/>
</svg>
</span>
</div>
<span
class="ant-collapse-header-text"
>
test panel1
</span>
</div>
</div>
<div
class="ant-collapse-item"
>
<div
aria-disabled="false"
aria-expanded="false"
class="ant-collapse-header"
role="button"
tabindex="0"
>
<div
class="ant-collapse-expand-icon"
>
<span
aria-label="right"
class="anticon anticon-right ant-collapse-arrow"
role="img"
>
<svg
aria-hidden="true"
data-icon="right"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 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 000-50.4z"
/>
</svg>
</span>
</div>
<span
class="ant-collapse-header-text"
>
test panel2
</span>
</div>
</div>
</div>
`;
exports[`Collapse could override default openMotion 1`] = `
<div
class="ant-collapse ant-collapse-icon-position-start"

View File

@ -237,4 +237,18 @@ describe('Collapse', () => {
});
});
});
it('Collapse.Panel usage', () => {
const { container } = render(
<Collapse bordered={false}>
<Collapse.Panel key="test panel1" header="test panel1">
test1
</Collapse.Panel>
<Collapse.Panel key="test panel2" header="test panel2">
test2
</Collapse.Panel>
</Collapse>,
);
expect(container.firstChild).toMatchSnapshot();
});
});