Skip to content

Commit 68deb2f

Browse files
committed
fix: simplify version switcher using UPopover
Replace UDropdownMenu with UPopover for more reliable click handling. Uses direct window.location.href navigation.
1 parent 82be198 commit 68deb2f

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

docs/components/AppVersionSwitcher.vue

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,41 @@ const currentVersionConfig = computed(() =>
1515
versions.find((v: Version) => v.value === currentVersion)
1616
)
1717
18-
const items = computed(() => {
18+
function getTargetUrl(version: Version): string {
1919
const currentBasePath = currentVersionConfig.value?.path?.replace(/\/$/, '') || '/flowforge'
2020
const currentPath = route.path
21+
const relativePath = currentPath.replace(new RegExp(`^${currentBasePath}`), '')
22+
return version.path.replace(/\/$/, '') + (relativePath || '/')
23+
}
2124
22-
return versions.map((version: Version) => {
23-
const relativePath = currentPath.replace(new RegExp(`^${currentBasePath}`), '')
24-
const targetPath = version.path.replace(/\/$/, '') + relativePath
25-
26-
return [{
27-
label: version.label,
28-
click: () => {
29-
window.location.href = targetPath || version.path
30-
}
31-
}]
32-
})
33-
})
25+
function switchVersion(version: Version): void {
26+
const url = getTargetUrl(version)
27+
window.location.href = url
28+
}
3429
</script>
3530

3631
<template>
37-
<UDropdownMenu
38-
v-if="versions.length > 1"
39-
:items="items"
40-
>
41-
<UButton
42-
variant="ghost"
43-
size="sm"
44-
:label="currentVersionConfig?.label || currentVersion"
45-
trailing-icon="i-lucide-chevron-down"
46-
/>
47-
</UDropdownMenu>
32+
<div v-if="versions.length > 1" class="relative">
33+
<UPopover>
34+
<UButton
35+
variant="ghost"
36+
size="sm"
37+
:label="currentVersionConfig?.label || currentVersion"
38+
trailing-icon="i-lucide-chevron-down"
39+
/>
40+
<template #content>
41+
<div class="p-1">
42+
<button
43+
v-for="version in versions"
44+
:key="version.value"
45+
class="w-full px-3 py-2 text-left text-sm rounded hover:bg-gray-100 dark:hover:bg-gray-800 flex items-center gap-2"
46+
:class="{ 'font-medium text-primary': version.value === currentVersion }"
47+
@click="switchVersion(version)"
48+
>
49+
{{ version.label }}
50+
</button>
51+
</div>
52+
</template>
53+
</UPopover>
54+
</div>
4855
</template>

0 commit comments

Comments
 (0)