diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md
index 46cad93b8b2..1fdd51b95db 100644
--- a/CHANGELOG.en-US.md
+++ b/CHANGELOG.en-US.md
@@ -14,6 +14,7 @@
- Fix `n-space`'s inner `display: grid` element breaks item height, closes `https://github.com/TuSimple/naive-ui/issues/546`.
- Fix `n-dropdown`'s `render-label` prop is invalid for group type option.
- Fix `n-descriptions` doesn't work with `v-for` children.
+- Fix `n-dialog` display an empty button when `positive-text` is not set, closes [#549](https://github.com/TuSimple/naive-ui/issues/549).
## 2.15.5 (2021-07-16)
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index a71d85a16ba..ba7f5901717 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -14,6 +14,7 @@
- 修复 `n-space` 中 `display: grid` 的元素显示不正确,关闭 `https://github.com/TuSimple/naive-ui/issues/546`
- 修复 `n-dropdown` 的 `render-label` 属性对 group 类型 option 失效
- 修复 `n-descriptions` 无法使用 `v-for` 的子元素
+- 修复 `n-dialog` `positive-text` 为空仍然显示按钮,关闭 [#549](https://github.com/TuSimple/naive-ui/issues/549)
## 2.15.5 (2021-07-16)
diff --git a/src/dialog/src/Dialog.tsx b/src/dialog/src/Dialog.tsx
index ea5cc39e0d3..294d5c5e233 100644
--- a/src/dialog/src/Dialog.tsx
+++ b/src/dialog/src/Dialog.tsx
@@ -185,6 +185,7 @@ export default defineComponent({
title,
content,
negativeText,
+ positiveText,
handlePositiveClick,
handleNegativeClick,
mergedTheme,
@@ -242,36 +243,40 @@ export default defineComponent({
{renderSlot($slots, 'default', undefined, () => [render(content)])}
-
- {renderSlot($slots, 'action', undefined, () => [
- negativeText ? (
-
- {{
- default: () => render(this.negativeText)
- }}
-
- ) : null,
-
- {{
- default: () => render(this.positiveText)
- }}
-
- ])}
-
+ {$slots.action || (!$slots.action && (positiveText || negativeText)) ? (
+
+ {renderSlot($slots, 'action', undefined, () => [
+ this.negativeText && (
+
+ {{
+ default: () => render(this.negativeText)
+ }}
+
+ ),
+ this.positiveText && (
+
+ {{
+ default: () => render(this.positiveText)
+ }}
+
+ )
+ ])}
+
+ ) : null}
)
}
diff --git a/src/dialog/src/styles/index.cssr.ts b/src/dialog/src/styles/index.cssr.ts
index a1f30f0f7bb..637b88f1ba5 100644
--- a/src/dialog/src/styles/index.cssr.ts
+++ b/src/dialog/src/styles/index.cssr.ts
@@ -76,7 +76,9 @@ export default c([
font-size: var(--font-size);
margin: var(--content-margin);
position: relative;
- `),
+ `, [
+ c('&:last-child', 'margin-bottom: 0;')
+ ]),
cE('action', `
display: flex;
justify-content: flex-end;
diff --git a/src/dialog/tests/Dialog.spec.tsx b/src/dialog/tests/Dialog.spec.tsx
index a066c50dcfe..c0c27342ccb 100644
--- a/src/dialog/tests/Dialog.spec.tsx
+++ b/src/dialog/tests/Dialog.spec.tsx
@@ -26,7 +26,9 @@ describe('n-dialog', () => {
return null
}
})
- const dialogProvider = mount(() => {{ default: () => }})
+ const dialogProvider = mount(() => (
+ {{ default: () => }}
+ ))
dialogProvider.unmount()
})
@@ -38,10 +40,17 @@ describe('n-dialog', () => {
content: 'success'
}
})
- expect(document.querySelector('.n-dialog__content')?.textContent).toEqual('success')
+ expect(document.querySelector('.n-dialog__content')?.textContent).toEqual(
+ 'success'
+ )
dialog.unmount()
})
+ it("shouldn't display button if no text is set", () => {
+ const wrapper = mount(NDialog)
+ expect(wrapper.find('button').exists()).toEqual(false)
+ })
+
it('async', async () => {
const Test = defineComponent({
setup () {