Skip to content

Commit a4f3f6d

Browse files
authored
feat(useOverlay): add isOpen method to check overlay state (#4041)
1 parent c5bdec0 commit a4f3f6d

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

docs/app/components/content/examples/modal/ModalProgrammaticExample.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const modal = overlay.create(LazyModalExample, {
1313
})
1414
1515
async function open() {
16-
const shouldIncrement = await modal.open()
16+
const instance = modal.open()
17+
18+
const shouldIncrement = await instance.result
1719
1820
if (shouldIncrement) {
1921
count.value++

docs/app/components/content/examples/slideover/SlideoverProgrammaticExample.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const slideover = overlay.create(LazySlideoverExample, {
1313
})
1414
1515
async function open() {
16-
const shouldIncrement = await slideover.open()
16+
const instance = slideover.open()
17+
18+
const shouldIncrement = await instance.result
1719
1820
if (shouldIncrement) {
1921
count.value++

docs/content/2.composables/use-overlay.md

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ Update an overlay using its `id`
6666

6767
Removes the overlay from the DOM using its `id`
6868

69+
- Parameters:
70+
- `id`: The identifier of the overlay
71+
72+
### `isOpen(id: symbol): boolean`
73+
74+
Checks if an overlay its open using its `id`
75+
6976
- Parameters:
7077
- `id`: The identifier of the overlay
7178

src/runtime/composables/useOverlay.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,21 @@ function _useOverlay() {
122122
return overlay
123123
}
124124

125+
const isOpen = (id: symbol): boolean => {
126+
const overlay = getOverlay(id)
127+
128+
return overlay.isOpen
129+
}
130+
125131
return {
126132
overlays,
127133
open,
128134
close,
129135
closeAll,
130136
create,
131137
patch,
132-
unMount
138+
unMount,
139+
isOpen
133140
}
134141
}
135142

0 commit comments

Comments
 (0)