11<template >
2+ <slot name =" activator" v-bind =" activatorAttrs" />
3+
24 <template v-if =" activatedOnce " >
35 <Teleport to =" body" >
46 <GDialogOverlay
@@ -128,22 +130,33 @@ export default defineComponent({
128130 },
129131 },
130132
131- emits: [' update:modelValue' ],
133+ emits: {
134+ ' update:modelValue' : (val : boolean ) => true ,
135+ },
132136
133137 setup(props , { emit }) {
134138 const contentFrame = ref <Element >()
135139 const overlay = ref <InstanceType <typeof GDialogOverlay >>()
136-
137140 const overlayElement = computed <Element | undefined >(() => overlay .value ?.$el as Element )
138141
139- const onClickOutside = () => {
140- if (! props .persistent ) {
141- emit (' update:modelValue' , false )
142- }
142+ const scopedModelValue = ref (props .modelValue )
143+
144+ watch (() => props .modelValue , (val ) => {
145+ scopedModelValue .value = val
146+ })
147+
148+ const onClose = () => {
149+ scopedModelValue .value = false
150+ emit (' update:modelValue' , false )
151+ }
152+
153+ const onOpen = () => {
154+ scopedModelValue .value = true
155+ emit (' update:modelValue' , true )
143156 }
144157
145158 const { activatedOnce, active : isActive, deactivating } = useLazyActivation (
146- computed (() => props . modelValue ),
159+ computed (() => scopedModelValue . value ),
147160 )
148161
149162 const { activeZIndex } = useStackable ({
@@ -165,6 +178,7 @@ export default defineComponent({
165178 zIndex: activeZIndex .value ,
166179 }))
167180
181+ // scroll
168182 const { enableScroll, disableScroll } = useScroll ({
169183 overlay: overlayElement ,
170184 content: contentFrame ,
@@ -185,6 +199,20 @@ export default defineComponent({
185199 enableScroll ()
186200 })
187201
202+ // click outside
203+ const onClickOutside = () => {
204+ if (! props .persistent ) {
205+ onClose ()
206+ }
207+ }
208+
209+ // activator slot
210+ const activatorAttrs = {
211+ onClick() {
212+ onOpen ()
213+ },
214+ }
215+
188216 return {
189217 onClickOutside ,
190218 activatedOnce ,
@@ -195,6 +223,7 @@ export default defineComponent({
195223 styles ,
196224 contentFrame ,
197225 overlay ,
226+ activatorAttrs ,
198227 }
199228 },
200229})
0 commit comments