Skip to content

Commit 8b47a70

Browse files
committed
fix: remove ready state check
1 parent f7c9d7c commit 8b47a70

3 files changed

Lines changed: 12 additions & 68 deletions

File tree

app/components/Modal.client.vue

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
<script setup lang="ts">
22
const props = defineProps<{
33
modalTitle: string
4-
whenReadyOnly?: boolean
54
}>()
65
7-
const emit = defineEmits<{
8-
(e: 'opened'): void
9-
(e: 'closed'): void
10-
}>()
11-
12-
const dialogRef = ref<HTMLDialogElement>()
13-
const isReady = ref(false)
6+
const dialogRef = useTemplateRef('dialogRef')
147
158
const modalTitleId = computed(() => {
169
const id = getCurrentInstance()?.attrs.id
@@ -21,25 +14,8 @@ function handleModalClose() {
2114
dialogRef.value?.close()
2215
}
2316
24-
function handleTransitionEnd(e: TransitionEvent) {
25-
if (e.target !== dialogRef.value) return
26-
if (e.propertyName !== 'opacity') return
27-
if (!dialogRef.value?.matches(':modal')) return
28-
29-
isReady.value = true
30-
emit('opened')
31-
}
32-
33-
function handleCloseEvent() {
34-
isReady.value = false
35-
emit('closed')
36-
}
37-
3817
defineExpose({
39-
showModal: () => {
40-
isReady.value = false
41-
dialogRef.value?.showModal()
42-
},
18+
showModal: () => dialogRef.value?.showModal(),
4319
close: () => dialogRef.value?.close(),
4420
})
4521
</script>
@@ -48,14 +24,12 @@ defineExpose({
4824
<Teleport to="body">
4925
<dialog
5026
ref="dialogRef"
51-
@transitionend="handleTransitionEnd"
52-
@close="handleCloseEvent"
5327
closedby="any"
5428
class="w-full bg-bg border border-border rounded-lg shadow-xl max-h-[90vh] overflow-y-auto overscroll-contain m-0 m-auto p-6 text-white"
55-
:class="props.whenReadyOnly ? (isReady ? 'modal-ready' : 'modal-not-ready') : ''"
5629
:aria-labelledby="modalTitleId"
5730
v-bind="$attrs"
5831
>
32+
<!-- Modal top header section -->
5933
<div class="flex items-center justify-between mb-6">
6034
<h2 :id="modalTitleId" class="font-mono text-lg font-medium">
6135
{{ modalTitle }}
@@ -69,13 +43,14 @@ defineExpose({
6943
<span class="i-carbon-close w-5 h-5" aria-hidden="true" />
7044
</button>
7145
</div>
72-
46+
<!-- Modal body content -->
7347
<slot />
7448
</dialog>
7549
</Teleport>
7650
</template>
7751

7852
<style scoped>
53+
/* Backdrop styling when any of the modals are open */
7954
dialog:modal::backdrop {
8055
@apply bg-black/60;
8156
}
@@ -102,15 +77,4 @@ dialog:modal {
10277
opacity: 0;
10378
}
10479
}
105-
106-
/* whenReadyOnly: keep it non-visible but allow opacity transition to run */
107-
.modal-not-ready:modal {
108-
visibility: hidden;
109-
pointer-events: none;
110-
}
111-
112-
.modal-ready:modal {
113-
visibility: visible;
114-
pointer-events: auto;
115-
}
11680
</style>

app/components/Package/ChartModal.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
<script setup lang="ts">
2-
defineEmits<{
3-
(e: 'opened'): void
4-
(e: 'closed'): void
5-
}>()
6-
</script>
1+
<script setup lang="ts"></script>
72

83
<template>
94
<Modal
10-
id="chart-modal"
11-
whenReadyOnly
125
:modalTitle="$t('package.downloads.modal_title')"
13-
@opened="$emit('opened')"
14-
@closed="$emit('closed')"
6+
id="chart-modal"
157
class="h-full sm:h-min sm:border sm:border-border sm:rounded-lg shadow-xl sm:max-h-[90vh] sm:max-w-3xl"
168
>
179
<div class="font-mono text-sm">

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ const props = defineProps<{
1111
const chartModal = useModal('chart-modal')
1212
1313
const isChartModalOpen = shallowRef(false)
14-
const isChartModalReady = shallowRef(false)
15-
16-
function openChartModal() {
14+
async function openChartModal() {
1715
isChartModalOpen.value = true
1816
// ensure the component renders before opening the dialog
19-
nextTick(() => chartModal.open())
20-
}
21-
22-
function handleCloseChartModal() {
23-
isChartModalOpen.value = false
24-
isChartModalReady.value = false
17+
await nextTick()
18+
await nextTick()
19+
chartModal.open()
2520
}
2621
2722
const { fetchPackageDownloadEvolution } = useCharts()
@@ -253,15 +248,8 @@ const config = computed(() => {
253248
</CollapsibleSection>
254249
</div>
255250

256-
<PackageChartModal
257-
v-if="isChartModalOpen"
258-
@close="isChartModalOpen = false"
259-
@opened="isChartModalReady = true"
260-
@closed="handleCloseChartModal"
261-
>
262-
<!-- The chart is only rendered when the dialog element has fully transitioned, to avoid the chart from triggering too early its internal auto-sizing -->
251+
<PackageChartModal v-if="isChartModalOpen" @close="isChartModalOpen = false">
263252
<PackageDownloadAnalytics
264-
v-if="isChartModalReady"
265253
:weeklyDownloads="weeklyDownloads"
266254
:inModal="true"
267255
:packageName="props.packageName"

0 commit comments

Comments
 (0)