Skip to content

Commit

Permalink
Fix flash of navbar & snippet toggler (directus#19047)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed Jun 30, 2023
1 parent 55f3d4c commit 78b2ca4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 4 additions & 6 deletions docs/.vitepress/components/SnippetToggler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
</template>

<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { onBeforeMount, ref, watch } from 'vue';
const props = defineProps<{
choices: string[];
label?: string;
}>();
const selected = ref(props.choices[0]);
const selected = ref();
const useStorage = (key: string) => {
const getStorageValue = () => {
Expand All @@ -55,12 +55,10 @@ const useStorage = (key: string) => {
const { getStorageValue, setStorageValue } = useStorage('toggler-value');
onMounted(() => {
onBeforeMount(() => {
const value = getStorageValue();
if (value) {
selected.value = value;
}
selected.value = value || props.choices[0];
watch(selected, (value) => {
setStorageValue(value);
Expand Down
3 changes: 2 additions & 1 deletion docs/.vitepress/theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Layout :class="{ isHome: path === '/' }">
<Layout :class="{ isHome }">
<template #doc-footer-before>
<Feedback :url="path" :title="title" />
<Contributors id="contributors" :contributors="contributors" />
Expand All @@ -19,6 +19,7 @@ const route = useRoute();
const title = computed(() => page.value.title);
const contributors = computed(() => page.value.frontmatter.contributors);
const path = computed(() => route.path);
const isHome = computed(() => ['/', '/index.html'].includes(path.value));
</script>

<style scoped>
Expand Down

0 comments on commit 78b2ca4

Please sign in to comment.