Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Collapse): 折叠事件穿透 #3581

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/collapse/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,13 @@ describe('CollapsePanel', () => {
});

describe('<slot>', () => {
test('default、header、headerRightContent', () => {
test('default', () => {
const wrapper = mount({
setup() {
return () => (
<Collapse>
<CollapsePanel ref="1" value="1">
{{
header: () => <h4>标题</h4>,
headerRightContent: () => <span>操作</span>,
default: () => <div>内容</div>,
}}
</CollapsePanel>
Expand All @@ -339,8 +337,44 @@ describe('CollapsePanel', () => {

const panel = wrapper.findComponent({ ref: '1' });
expect(panel.find('.t-collapse-panel__content > div').html()).toBe('<div>内容</div>');
});

test('header', () => {
const wrapper = mount({
setup() {
return () => (
<Collapse>
<CollapsePanel ref="1" value="1">
{{
header: () => <h4>标题</h4>,
}}
</CollapsePanel>
</Collapse>
);
},
});

const panel = wrapper.findComponent({ ref: '1' });
expect(panel.find('.t-collapse-panel__header > h4').html()).toBe('<h4>标题</h4>');
expect(panel.find('.t-collapse-panel__header > span').html()).toBe('<span>操作</span>');
});

test('headerRightContent', () => {
const wrapper = mount({
setup() {
return () => (
<Collapse>
<CollapsePanel ref="1" value="1">
{{
headerRightContent: () => <span>操作</span>,
}}
</CollapsePanel>
</Collapse>
);
},
});

const panel = wrapper.findComponent({ ref: '1' });
expect(panel.find('.t-collapse-panel__header > div > span').html()).toBe('<span>操作</span>');
});

test('content', () => {
Expand Down
11 changes: 10 additions & 1 deletion src/collapse/collapse-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default defineComponent({
}
e.stopPropagation();
};
const handleHeaderRightContentClick = (e: MouseEvent) => {
e.stopPropagation();
};
const renderDefaultIcon = () => {
return <FakeArrow overlayClassName={`${componentName.value}__icon--default`} />;
};
Expand All @@ -70,19 +73,25 @@ export default defineComponent({
const renderBlank = () => {
return <div class={`${componentName.value}__header--blank`}></div>;
};
const renderHeaderRightContent = () => {
const headerRightContent = renderTNodeJSX('headerRightContent');

return headerRightContent ? <div onClick={handleHeaderRightContentClick}>{headerRightContent}</div> : null;
};
const renderHeader = () => {
const cls = [
`${componentName.value}__header`,
{
[clickableClass.value]: expandOnRowClick.value && !isDisabled.value,
},
];

return (
<div class={cls} onClick={handleClick}>
{expandIconPlacement.value === 'left' && renderIcon()}
{renderTNodeJSX('header')}
{renderBlank()}
{renderTNodeJSX('headerRightContent')}
{renderHeaderRightContent()}
{expandIconPlacement.value === 'right' && renderIcon()}
</div>
);
Expand Down
Loading