Skip to content

Commit f80d683

Browse files
authored
feat(modal): [modal] add show-close feature (#2840)
* feat: add new features to modal components (show-close) * fix: modify e2e-test * fix: revise inspection comments
1 parent 82f2309 commit f80d683

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

examples/sites/demos/apis/modal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,16 @@ export default {
330330
{
331331
name: 'show-close',
332332
type: 'Boolean',
333-
defaultValue: '',
333+
defaultValue: 'true',
334334
desc: {
335335
'zh-CN': '是否显示关闭按钮,默认值为 true',
336336
'en-US': ''
337337
},
338-
mode: ['mobile-first'],
338+
meta: {
339+
stable: '3.22.0'
340+
},
341+
mode: ['pc', 'mobile-first'],
342+
pcDemo: 'modal-other',
339343
mfDemo: ''
340344
},
341345
{

examples/sites/demos/pc/app/modal/modal-other-composition-api.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
show-footer
1717
v-bind="options"
1818
:esc-closable="true"
19+
show-close
1920
>
2021
<tiny-form :model="createData" label-width="100px">
2122
<tiny-form-item label="用户名" prop="username">
@@ -58,6 +59,7 @@ function btnClick() {
5859
title: '自定义弹窗标题',
5960
showHeader: true,
6061
showFooter: true,
62+
showClose: false,
6163
...options.value
6264
})
6365
}

examples/sites/demos/pc/app/modal/modal-other.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { test, expect } from '@playwright/test'
22

33
test('弹窗其他特性', async ({ page }) => {
44
page.on('pageerror', (exception) => expect(exception).toBeNull())
5+
const close = page.locator('.tiny-modal__close-btn > .tiny-svg')
56
await page.goto('modal#modal-other')
67
await page.getByRole('button', { name: '弹窗 esc 关闭' }).first().click()
8+
await expect(close).toBeHidden()
79
await page.locator('body').press('Escape')
810
await page.getByRole('button', { name: '弹窗 esc 关闭,保留表单数据' }).click()
911
await page.locator('body').press('Escape')

examples/sites/demos/pc/app/modal/modal-other.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
show-footer
1717
v-bind="options"
1818
:esc-closable="true"
19+
show-close
1920
>
2021
<tiny-form :model="createData" label-width="100px">
2122
<tiny-form-item label="用户名" prop="username">
@@ -62,6 +63,7 @@ export default {
6263
title: '自定义弹窗标题',
6364
showHeader: true,
6465
showFooter: true,
66+
showClose: false,
6567
...this.options
6668
})
6769
},

examples/sites/demos/pc/app/modal/webdoc/modal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ export default {
203203
'zh-CN': `
204204
通过<code>esc-closable</code>属性设置是否允许按 Esc 键关闭窗口。默认值为<code>false</code><br>
205205
通过<code>z-index</code>属性设置自定义堆叠顺序。<br>
206+
通过<code>show-close</code>属性设置自定义是否显示关闭按钮。默认值为<code>true</code><br>
206207
通过<code>is-form-reset</code>属性,设置关闭弹窗后,是否重置数据。默认值为<code>true</code>,即关闭弹窗后重置数据。<br>
207208
`,
208209
'en-US': `
209210
The <code>esc-closable</code> property sets whether to allow the Esc key to close the window. The default value is <code>false</code><br>
210211
You can set a custom stack order using the <code>z-index</code> property. <br>
212+
Customize whether to display a close button through the<code>show-close</code>attribute. The default value is<code>true</code><br>
211213
You can use the <code>is-form-reset</code> property to set whether data is reset after modal is closed. The default value is <code>true</code>, that is, the data is reset after the modal window is closed. <br>
212214
`
213215
},

packages/vue/src/modal/src/pc.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default defineComponent({
6868
'cancelBtnProps',
6969
'footerDragable',
7070
'tiny_theme',
71-
'slots'
71+
'slots',
72+
'showClose'
7273
],
7374
emits: [
7475
'update:modelValue',
@@ -88,7 +89,19 @@ export default defineComponent({
8889
return setup({ props, context, renderless, api }) as unknown as IModalApi
8990
},
9091
render() {
91-
let { $props = {}, state, scopedSlots, vSize, type, resize, animat, status, showHeader, messageClosable } = this
92+
let {
93+
$props = {},
94+
state,
95+
scopedSlots,
96+
vSize,
97+
type,
98+
resize,
99+
showClose,
100+
animat,
101+
status,
102+
showHeader,
103+
messageClosable
104+
} = this
92105
let { showFooter, title, message, lockScroll, lockView, mask, _constants: constants, t } = this
93106
let { confirmContent, cancelContent, confirmBtnProps, cancelBtnProps } = this
94107
let { zoomLocat, visible, contentVisible, modalTop, isMsg } = state
@@ -199,12 +212,14 @@ export default defineComponent({
199212
}
200213
})
201214
: null,
202-
h(iconClose(), {
203-
class: ['tiny-modal__close-btn', 'trigger__btn'],
204-
on: {
205-
click: this.closeEvent
206-
}
207-
})
215+
showClose
216+
? h(iconClose(), {
217+
class: ['tiny-modal__close-btn', 'trigger__btn'],
218+
on: {
219+
click: this.closeEvent
220+
}
221+
})
222+
: null
208223
]
209224
)
210225
: null,

0 commit comments

Comments
 (0)