Fix project chooser not closing on click (#611)

This commit is contained in:
Rijk van Zanten
2020-05-22 11:36:51 -04:00
committed by GitHub
parent 3b4bc9d2d0
commit dbe4d319a9

View File

@@ -1,12 +1,24 @@
<template>
<div class="project-chooser" :class="{ active }">
<button class="toggle" :disabled="projects.length === 1" @click="active = !active">
<button
ref="activator"
class="toggle"
:disabled="projects.length === 1"
@click="active = !active"
>
<latency-indicator />
<span class="name">{{ currentProject.name }}</span>
<v-icon class="icon" name="expand_more" />
</button>
<transition-expand>
<div v-if="active" class="options-wrapper" v-click-outside="() => (active = false)">
<div
v-if="active"
class="options-wrapper"
v-click-outside="{
handler: () => (active = false),
middleware: onClickOutsideMiddleware,
}"
>
<div class="options">
<v-divider />
@@ -40,6 +52,7 @@ export default defineComponent({
const projectsStore = useProjectsStore();
const { currentProjectKey } = toRefs(projectsStore.state);
const active = ref(false);
const activator = ref<Element>(null);
const currentProject = projectsStore.currentProject;
@@ -50,8 +63,14 @@ export default defineComponent({
projectsStore,
currentProject,
active,
onClickOutsideMiddleware,
activator,
};
function onClickOutsideMiddleware(event: Event) {
return !activator.value?.contains(event.target as Node);
}
function navigateToProject(key: string) {
router
.push(`/${key}/collections`)