fix(dialog): on-esc (#3360)

Signed-off-by: Sepush <sepush@outlook.com>
This commit is contained in:
Sepush 2022-07-27 22:31:47 +08:00 committed by GitHub
parent 9a452489c9
commit 58513a4d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -28,6 +28,9 @@ export default defineComponent({
maskClosable: false,
onMaskClick: () => {
message.success('cannot close')
},
onEsc: () => {
message.success('close by esc')
}
})
}

View File

@ -29,6 +29,9 @@ export default defineComponent({
maskClosable: false,
onMaskClick: () => {
message.success('不能关闭')
},
onEsc: () => {
message.success('通过 esc 关闭')
}
})
}

View File

@ -90,6 +90,13 @@ export const NDialogEnvironment = defineComponent({
maskClosable && hide()
}
}
function handleEsc (): void {
const { onEsc, closeOnEsc } = props
if (onEsc) {
onEsc()
closeOnEsc && hide()
}
}
function hide (): void {
showRef.value = false
}
@ -104,7 +111,8 @@ export const NDialogEnvironment = defineComponent({
handleCloseClick,
handleNegativeClick,
handlePositiveClick,
handleMaskClick
handleMaskClick,
handleEsc
}
},
render () {
@ -115,6 +123,7 @@ export const NDialogEnvironment = defineComponent({
handleCloseClick,
handleAfterLeave,
handleMaskClick,
handleEsc,
to,
maskClosable,
show
@ -124,6 +133,7 @@ export const NDialogEnvironment = defineComponent({
show={show}
onUpdateShow={handleUpdateShow}
onMaskClick={handleMaskClick}
onEsc={handleEsc}
to={to}
maskClosable={maskClosable}
onAfterLeave={handleAfterLeave}