Skip to content

Commit d0e7230

Browse files
authored
fix(modal): 当duration为0时不自动关闭弹窗 (#3994)
* fix(modal): 当duration为0时不自动关闭弹窗 * docs(modal): 补充duration属性说明(duration为0时不自动关闭) * docs(modal): 修复duration属性英文描述的标点错误
1 parent 703135a commit d0e7230

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

examples/sites/demos/apis/modal.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export default {
9393
type: 'number | string',
9494
defaultValue: '3000',
9595
desc: {
96-
'zh-CN': "自动关闭的延时,仅当 type 为 'message' 有效",
97-
'en-US': "Delay for automatic shutdown, only valid when type is 'message'"
96+
'zh-CN': "自动关闭的延时,仅当 type 为 'message' 有效,如果设置为0则窗口不会自动关闭",
97+
'en-US':
98+
"Delay for automatic shutdown, only valid when type is 'message', If set to 0, the popup will not close automatically"
9899
},
99100
mode: ['pc', 'mobile-first'],
100101
pcDemo: 'message-close',

examples/sites/demos/mobile-first/app/modal/webdoc/modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export default {
5858
'en-US': 'events'
5959
},
6060
desc: {
61-
'zh-CN': '<p>可通过 `duration` 属性设置自动关闭的延迟时间,只对 type=message 有效。<p>',
61+
'zh-CN':
62+
'<p>可通过 `duration` 属性设置自动关闭的延迟时间,只对 type=message 有效,如果设置为0则窗口不会自动关闭。<p>',
6263
'en-US': '<p>bbutton click</p>'
6364
},
6465
codeFiles: ['duration.vue']

packages/renderless/src/modal/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ export const mouseLeaveEvent =
164164
(): void => {
165165
api.addMsgQueue()
166166

167-
state.timer = window.setTimeout(
168-
() => {
167+
const duration = parseFloat(props.duration as string)
168+
if (duration > 0) {
169+
state.timer = window.setTimeout(() => {
169170
api.close('close')
170-
},
171-
parseFloat(props.duration as string)
172-
)
171+
}, duration)
172+
}
173173
}
174174

175175
export const updateZindex =
@@ -268,12 +268,12 @@ export const open =
268268
if (state.isMsg) {
269269
api.addMsgQueue()
270270

271-
state.timer = window.setTimeout(
272-
() => {
271+
const duration = parseFloat(props.duration as string)
272+
if (duration > 0) {
273+
state.timer = window.setTimeout(() => {
273274
api.close(params.type)
274-
},
275-
parseFloat(props.duration as string)
276-
)
275+
}, duration)
276+
}
277277
} else {
278278
nextTick(() => {
279279
if (!isMobileFirstMode) {

0 commit comments

Comments
 (0)