Skip to content

Commit 3fc72d2

Browse files
authored
Merge pull request #195 from yel-hadd/STAR-71-search-drawer-not-closing
STAR-71: Search drawer fixes — close on click + initial-load animation flash
2 parents 42ad374 + f88e7a3 commit 3fc72d2

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

docs/.vuepress/theme/drawer/Drawer.vue

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<div class="drawer" :class="{'is-open': isOpenDrawer}">
3+
<div class="drawer" :class="{'is-open': isOpenDrawer, 'drawer--animated': animationsReady}">
44
<div class="drawer-header">
55
<div class="drawer-header__wrapper">
66
<h2 class="drawer-header__paragraph">How can we help you?</h2>
@@ -17,7 +17,7 @@
1717
<div class="drawer-main__breadcrumb">
1818
<!-- Optional breadcrumb can stay here -->
1919
</div>
20-
<DrawerSearchResult :modelValue="modelValue" :data="drawerArticleResult"/>
20+
<DrawerSearchResult :modelValue="modelValue" :data="drawerArticleResult" @closeDrawer="onCloseDrawer"/>
2121
</div>
2222
</div>
2323
<Footer v-if="isOpenDrawer && isMobileWidth" class="drawer-footer__mobile"/>
@@ -30,7 +30,7 @@
3030
<script setup>
3131
import { withBase } from "@vuepress/client";
3232
import Footer from "../footer/Footer.vue";
33-
import { computed, ref, watch } from "vue";
33+
import { computed, onMounted, ref, watch } from "vue";
3434
import DrawerSearchResult from "./DrawerSearchResult.vue";
3535
3636
const props = defineProps({
@@ -66,6 +66,16 @@ const onCloseDrawer = () => {
6666
emit('closeDrawer');
6767
}
6868
69+
// The drawer starts hidden (translateY(-100%)). Enabling the slide transition
70+
// only after the first paint prevents the close animation from flashing on
71+
// initial page load — it then fires only on genuine open/close toggles.
72+
const animationsReady = ref(false);
73+
onMounted(() => {
74+
requestAnimationFrame(() => requestAnimationFrame(() => {
75+
animationsReady.value = true;
76+
}));
77+
});
78+
6979
watch(() => props.isOpenDrawer, () => {
7080
document.body.classList.toggle('disable-scroll', props.isOpenDrawer);
7181
});
@@ -89,7 +99,12 @@ watch(() => props.isOpenDrawer, () => {
8999
background: $drawerHeaderBgColor
90100
opacity: 0;
91101
transform: translateY(-100%);
92-
transition: 0.4s ease;
102+
103+
// Transition is intentionally NOT set here so the initial hidden state is
104+
// applied instantly (no flash on first load). It is enabled via
105+
// .drawer--animated once the component has mounted.
106+
&.drawer--animated
107+
transition: 0.4s ease
93108
94109
&-header
95110
padding 1.25rem $layout-horizontal-padding

docs/.vuepress/theme/drawer/DrawerSearchResult.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ const props = defineProps({
6161
const { MAX_VISIBLE_RESULT } = inject("themeConfig");
6262
const isShowAllResult = ref(false);
6363
64+
const emit = defineEmits(["closeDrawer"]);
65+
6466
const gotTo = (url) => {
67+
// Always close the search drawer on click. When the target resolves to the
68+
// page we are already on (same pathname, only the #hash differs) the browser
69+
// does NOT reload, so the drawer would otherwise stay open over the page and
70+
// the result would look unclickable (STAR-71).
71+
emit("closeDrawer");
6572
const parsedCurrentUrl = new URL(window.location.href);
6673
if (parsedCurrentUrl.pathname + parsedCurrentUrl.hash === url) {
6774
window.location.reload();

0 commit comments

Comments
 (0)