Skip to content

Commit 8d1d64e

Browse files
committed
FaDrawerFaModal 组件新增 destroyOnClose 属性
1 parent 3259ef0 commit 8d1d64e

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/ui/components/FaDrawer/index.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const props = withDefaults(
3636
footer?: boolean
3737
closeOnClickOverlay?: boolean
3838
closeOnPressEscape?: boolean
39+
destroyOnClose?: boolean
3940
contentClass?: HTMLAttributes['class']
4041
headerClass?: HTMLAttributes['class']
4142
footerClass?: HTMLAttributes['class']
@@ -59,6 +60,7 @@ const props = withDefaults(
5960
footer: true,
6061
closeOnClickOverlay: true,
6162
closeOnPressEscape: true,
63+
destroyOnClose: true,
6264
},
6365
)
6466
@@ -81,6 +83,20 @@ watch(() => props.modelValue, (newValue) => {
8183
isOpen.value = newValue
8284
})
8385
86+
const hasOpened = ref(false)
87+
const isClosed = ref(true)
88+
89+
watch(() => isOpen.value, (value) => {
90+
isClosed.value = false
91+
if (value && !hasOpened.value) {
92+
hasOpened.value = true
93+
}
94+
}, {
95+
immediate: true,
96+
})
97+
98+
const forceMount = computed(() => !props.destroyOnClose && hasOpened.value)
99+
84100
function updateOpen(value: boolean) {
85101
isOpen.value = value
86102
emits('update:modelValue', value)
@@ -127,6 +143,7 @@ function handleAnimationEnd() {
127143
}
128144
else {
129145
emits('closed')
146+
isClosed.value = true
130147
}
131148
}
132149
</script>
@@ -138,8 +155,11 @@ function handleAnimationEnd() {
138155
:open="isOpen"
139156
:overlay="props.overlay"
140157
:overlay-blur="props.overlayBlur"
141-
:class="cn('w-full flex flex-col gap-0 p-0', props.contentClass)"
158+
:class="cn('w-full flex flex-col gap-0 p-0', props.contentClass, {
159+
hidden: isClosed,
160+
})"
142161
:side="props.side"
162+
:force-mount="forceMount"
143163
@open-auto-focus="handleFocusOutside"
144164
@close-auto-focus="handleFocusOutside"
145165
@focus-outside="handleFocusOutside"

src/ui/components/FaModal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ModalProps {
3030
footer?: boolean
3131
closeOnClickOverlay?: boolean
3232
closeOnPressEscape?: boolean
33+
destroyOnClose?: boolean
3334
class?: HTMLAttributes['class']
3435
headerClass?: HTMLAttributes['class']
3536
contentClass?: HTMLAttributes['class']

src/ui/components/FaModal/index.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const props = withDefaults(
4040
footer: true,
4141
closeOnClickOverlay: true,
4242
closeOnPressEscape: true,
43+
destroyOnClose: true,
4344
},
4445
)
4546
@@ -68,6 +69,20 @@ watch(() => props.modelValue, (newValue) => {
6869
isOpen.value = newValue
6970
})
7071
72+
const hasOpened = ref(false)
73+
const isClosed = ref(true)
74+
75+
watch(() => isOpen.value, (value) => {
76+
isClosed.value = false
77+
if (value && !hasOpened.value) {
78+
hasOpened.value = true
79+
}
80+
}, {
81+
immediate: true,
82+
})
83+
84+
const forceMount = computed(() => !props.destroyOnClose && hasOpened.value)
85+
7186
const { isDragging, transform } = useDraggable(
7287
dialogRef,
7388
dialogHeaderRef,
@@ -186,6 +201,7 @@ function handleAnimationEnd() {
186201
}
187202
else {
188203
emits('closed')
204+
isClosed.value = true
189205
}
190206
}
191207
</script>
@@ -201,10 +217,12 @@ function handleAnimationEnd() {
201217
:overlay-blur="props.overlayBlur"
202218
:maximize="isMaximize"
203219
:maximizable="props.maximizable"
220+
:force-mount="forceMount"
204221
:class="cn('left-0 right-0 top-0 md:top-[5vh] flex flex-col p-0 gap-0 mx-auto h-[calc-size(auto,size)] min-h-full md:min-h-auto max-h-full md:max-h-[90vh] translate-x-0 translate-y-0', props.class, {
205222
'md:top-0 size-full max-w-full max-h-full md:max-h-full': isMaximize,
206223
'md:top-1/2 md:-translate-y-1/2!': props.alignCenter,
207224
'duration-0': isDragging,
225+
'hidden': isClosed,
208226
})"
209227
@open-auto-focus="handleFocusOutside"
210228
@close-auto-focus="handleFocusOutside"

0 commit comments

Comments
 (0)