Skip to content

Commit

Permalink
fix(dialog): display an empty button when positive-text is not set, f…
Browse files Browse the repository at this point in the history
…ix #549
  • Loading branch information
07akioni committed Jul 21, 2021
1 parent b29f32f commit dab555d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
65 changes: 35 additions & 30 deletions src/dialog/src/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default defineComponent({
title,
content,
negativeText,
positiveText,
handlePositiveClick,
handleNegativeClick,
mergedTheme,
Expand Down Expand Up @@ -242,36 +243,40 @@ export default defineComponent({
<div class={`${mergedClsPrefix}-dialog__content`}>
{renderSlot($slots, 'default', undefined, () => [render(content)])}
</div>
<div class={`${mergedClsPrefix}-dialog__action`}>
{renderSlot($slots, 'action', undefined, () => [
negativeText ? (
<NButton
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
ghost
size="small"
onClick={handleNegativeClick}
>
{{
default: () => render(this.negativeText)
}}
</NButton>
) : null,
<NButton
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
disabled={loading}
loading={loading}
size="small"
type={type === 'default' ? 'primary' : type}
onClick={handlePositiveClick}
>
{{
default: () => render(this.positiveText)
}}
</NButton>
])}
</div>
{$slots.action || (!$slots.action && (positiveText || negativeText)) ? (
<div class={`${mergedClsPrefix}-dialog__action`}>
{renderSlot($slots, 'action', undefined, () => [
this.negativeText && (
<NButton
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
ghost
size="small"
onClick={handleNegativeClick}
>
{{
default: () => render(this.negativeText)
}}
</NButton>
),
this.positiveText && (
<NButton
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
disabled={loading}
loading={loading}
size="small"
type={type === 'default' ? 'primary' : type}
onClick={handlePositiveClick}
>
{{
default: () => render(this.positiveText)
}}
</NButton>
)
])}
</div>
) : null}
</div>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/dialog/src/styles/index.cssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions src/dialog/tests/Dialog.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ describe('n-dialog', () => {
return null
}
})
const dialogProvider = mount(() => <Provider>{{ default: () => <Test /> }}</Provider>)
const dialogProvider = mount(() => (
<Provider>{{ default: () => <Test /> }}</Provider>
))
dialogProvider.unmount()
})

Expand All @@ -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 () {
Expand Down

0 comments on commit dab555d

Please sign in to comment.