|
32 | 32 |
|
33 | 33 | <div v-if="showWorkspaceSwitcher" class="relative"> |
34 | 34 | <Button |
| 35 | + ref="workspaceSwitcherTrigger" |
35 | 36 | v-tooltip="{ value: workspaceName, showDelay: 300 }" |
36 | 37 | variant="muted-textonly" |
37 | 38 | class="flex h-auto w-full items-center justify-between rounded-lg px-4 py-2 hover:bg-secondary-background-hover" |
38 | 39 | :aria-expanded="isWorkspaceSwitcherOpen" |
| 40 | + aria-haspopup="menu" |
| 41 | + aria-controls="workspace-switcher-panel" |
39 | 42 | data-testid="workspace-switcher-trigger" |
40 | 43 | @click="isWorkspaceSwitcherOpen = !isWorkspaceSwitcherOpen" |
| 44 | + @keydown.escape.stop="isWorkspaceSwitcherOpen = false" |
41 | 45 | > |
42 | 46 | <div class="flex w-0 flex-1 items-center gap-2"> |
43 | 47 | <WorkspaceProfilePic |
|
53 | 57 |
|
54 | 58 | <div |
55 | 59 | v-if="isWorkspaceSwitcherOpen" |
| 60 | + id="workspace-switcher-panel" |
| 61 | + ref="workspaceSwitcherPanel" |
| 62 | + role="menu" |
56 | 63 | class="absolute top-0 right-full z-10 mr-4 rounded-lg border border-border-default bg-base-background shadow-[1px_1px_8px_0_rgba(0,0,0,0.4)]" |
57 | 64 | data-testid="workspace-switcher-panel" |
58 | 65 | > |
|
145 | 152 | </template> |
146 | 153 |
|
147 | 154 | <script setup lang="ts"> |
| 155 | +import { onClickOutside } from '@vueuse/core' |
148 | 156 | import { storeToRefs } from 'pinia' |
149 | 157 | import Divider from 'primevue/divider' |
150 | 158 | import Skeleton from 'primevue/skeleton' |
151 | | -import { computed, onMounted, ref } from 'vue' |
| 159 | +import { computed, onMounted, ref, useTemplateRef } from 'vue' |
152 | 160 | import { useI18n } from 'vue-i18n' |
153 | 161 |
|
154 | 162 | import { formatCreditsFromCents } from '@/base/credits/comfyCredits' |
@@ -191,6 +199,17 @@ const { initState, workspaces, workspaceName } = storeToRefs( |
191 | 199 | useTeamWorkspaceStore() |
192 | 200 | ) |
193 | 201 | const isWorkspaceSwitcherOpen = ref(false) |
| 202 | +const workspaceSwitcherTrigger = useTemplateRef('workspaceSwitcherTrigger') |
| 203 | +const workspaceSwitcherPanel = useTemplateRef('workspaceSwitcherPanel') |
| 204 | +
|
| 205 | +onClickOutside( |
| 206 | + workspaceSwitcherPanel, |
| 207 | + () => { |
| 208 | + isWorkspaceSwitcherOpen.value = false |
| 209 | + }, |
| 210 | + { ignore: [workspaceSwitcherTrigger] } |
| 211 | +) |
| 212 | +
|
194 | 213 | const showWorkspaceSwitcher = computed( |
195 | 214 | () => initState.value === 'ready' && workspaces.value.length > 0 |
196 | 215 | ) |
|
0 commit comments