mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 11:20:36 +01:00
feat(Modal/Slideover): emit close-prevented event (#1207)
This commit is contained in:
committed by
GitHub
parent
ac5224cbae
commit
6faf15bc74
@@ -33,7 +33,7 @@ Set the `transition` prop to `false` to disable it.
|
|||||||
|
|
||||||
### Prevent close
|
### Prevent close
|
||||||
|
|
||||||
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut.
|
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut. A `close-prevented` event will be emitted when the user tries to close the modal.
|
||||||
|
|
||||||
:component-example{component="modal-example-prevent-close"}
|
:component-example{component="modal-example-prevent-close"}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ Set the `transition` prop to `false` to disable it.
|
|||||||
|
|
||||||
### Prevent close
|
### Prevent close
|
||||||
|
|
||||||
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut.
|
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut. A `close-prevented` event will be emitted when the user tries to close the modal.
|
||||||
|
|
||||||
:component-example{component="slideover-example-prevent-close"}
|
:component-example{component="slideover-example-prevent-close"}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<TransitionRoot :appear="appear" :show="isOpen" as="template">
|
<TransitionRoot :appear="appear" :show="isOpen" as="template">
|
||||||
<HDialog :class="ui.wrapper" v-bind="attrs" @close="(e) => !preventClose && close(e)">
|
<HDialog :class="ui.wrapper" v-bind="attrs" @close="close">
|
||||||
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
|
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
|
||||||
<div :class="[ui.overlay.base, ui.overlay.background]" />
|
<div :class="[ui.overlay.base, ui.overlay.background]" />
|
||||||
</TransitionChild>
|
</TransitionChild>
|
||||||
@@ -81,7 +81,7 @@ export default defineComponent({
|
|||||||
default: () => ({})
|
default: () => ({})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue', 'close'],
|
emits: ['update:modelValue', 'close', 'close-prevented'],
|
||||||
setup (props, { emit }) {
|
setup (props, { emit }) {
|
||||||
const { ui, attrs } = useUI('modal', toRef(props, 'ui'), config, toRef(props, 'class'))
|
const { ui, attrs } = useUI('modal', toRef(props, 'ui'), config, toRef(props, 'class'))
|
||||||
|
|
||||||
@@ -105,6 +105,12 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function close (value: boolean) {
|
function close (value: boolean) {
|
||||||
|
if (props.preventClose) {
|
||||||
|
emit('close-prevented')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
isOpen.value = value
|
isOpen.value = value
|
||||||
|
|
||||||
emit('close')
|
emit('close')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<TransitionRoot as="template" :appear="appear" :show="isOpen">
|
<TransitionRoot as="template" :appear="appear" :show="isOpen">
|
||||||
<HDialog :class="[ui.wrapper, { 'justify-end': side === 'right' }]" v-bind="attrs" @close="(e) => !preventClose && close(e)">
|
<HDialog :class="[ui.wrapper, { 'justify-end': side === 'right' }]" v-bind="attrs" @close="close">
|
||||||
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
|
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
|
||||||
<div :class="[ui.overlay.base, ui.overlay.background]" />
|
<div :class="[ui.overlay.base, ui.overlay.background]" />
|
||||||
</TransitionChild>
|
</TransitionChild>
|
||||||
@@ -70,7 +70,7 @@ export default defineComponent({
|
|||||||
default: () => ({})
|
default: () => ({})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue', 'close'],
|
emits: ['update:modelValue', 'close', 'close-prevented'],
|
||||||
setup (props, { emit }) {
|
setup (props, { emit }) {
|
||||||
const { ui, attrs } = useUI('slideover', toRef(props, 'ui'), config, toRef(props, 'class'))
|
const { ui, attrs } = useUI('slideover', toRef(props, 'ui'), config, toRef(props, 'class'))
|
||||||
|
|
||||||
@@ -98,6 +98,12 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function close (value: boolean) {
|
function close (value: boolean) {
|
||||||
|
if (props.preventClose) {
|
||||||
|
emit('close-prevented')
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
isOpen.value = value
|
isOpen.value = value
|
||||||
emit('close')
|
emit('close')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user