Skip to content

Commit

Permalink
fix(Dialog): don't render header dom when header and closeBtn are fal…
Browse files Browse the repository at this point in the history
…se (#4841)

* fix(Dialog): don't render header dom when header and closeBtn are false

* fix(Dialog): compatible "header === 0" special case
  • Loading branch information
ylunwang authored Dec 17, 2024
1 parent 47a7886 commit 94b7966
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/dialog/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ describe('Dialog', () => {
expect(header.text()).toBe('this is header');
});

it(':header:false', async () => {
const visible = ref(true);
const wrapper = mount(() => (
<Dialog v-model:visible={visible.value} header={false} closeBtn={false} body="this is content"></Dialog>
));
const header = wrapper.find('.t-dialog__header');
await nextTick();
expect(header.exists()).toBeFalsy();
});

it(':placement', async () => {
const placementList = ['top', 'center'];
const visible = ref(true);
Expand Down
31 changes: 18 additions & 13 deletions src/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ export default defineComponent({
})}
</div>
);

const headerContent = renderTNodeJSX('header', defaultHeader);

const footerContent = renderTNodeJSX('footer', defaultFooter);

const headerClassName = isFullScreen.value
? [`${COMPONENT_NAME.value}__header`, `${COMPONENT_NAME.value}__header--fullscreen`]
: `${COMPONENT_NAME.value}__header`;
Expand All @@ -341,8 +346,6 @@ export default defineComponent({
const bodyClassName =
props.theme === 'default' ? [`${COMPONENT_NAME.value}__body`] : [`${COMPONENT_NAME.value}__body__icon`];

const footerContent = renderTNodeJSX('footer', defaultFooter);

if (isFullScreen.value && footerContent) {
bodyClassName.push(`${COMPONENT_NAME.value}__body--fullscreen`);
} else if (isFullScreen.value) {
Expand Down Expand Up @@ -374,18 +377,20 @@ export default defineComponent({
v-draggable={isModeLess.value && props.draggable}
ref={dialogEle}
>
<div class={headerClassName} onMousedown={onStopDown}>
<div class={`${COMPONENT_NAME.value}__header-content`}>
{getIcon()}
{renderTNodeJSX('header', defaultHeader)}
{(headerContent || headerContent === 0 || props.closeBtn) && (
<div class={headerClassName} onMousedown={onStopDown}>
<div class={`${COMPONENT_NAME.value}__header-content`}>
{getIcon()}
{headerContent}
</div>

{props.closeBtn ? (
<span class={closeClassName} onClick={closeBtnAction}>
{renderTNodeJSX('closeBtn', defaultCloseBtn)}
</span>
) : null}
</div>

{props.closeBtn ? (
<span class={closeClassName} onClick={closeBtnAction}>
{renderTNodeJSX('closeBtn', defaultCloseBtn)}
</span>
) : null}
</div>
)}
<div class={bodyClassName} onMousedown={onStopDown}>
{body}
</div>
Expand Down

0 comments on commit 94b7966

Please sign in to comment.