You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In the VuePress default theme, you can swipe left-to-right to open the sidebar. See for example on https://vuepress.vuejs.org/ (if on desktop, emulate phone mode in dev tools).
Vitepress' default theme does not have that feature, even though it would be nice. More importantly, I could not figure out how to use useSidebar to implement it myself (see below).
Describe the solution you'd like
Add this small feature (potentially as an option) to the default theme and/or enable users of VitePress to implement such thnigs themselves by extending the default theme.
Describe alternatives you've considered
Here are some approaches I attempted, none work. The code for the swipe logic is adapted from VuePress' default-theme and works great, the problem seems to be with my use of useSidebar.
Extending default theme with custom layout
<!-- .vitepress/theme/CustomLayout.vue --><scriptsetuplang="ts">importDefaultThemefrom"vitepress/theme";import { useSidebar } from"vitepress/theme";const { Layout } =DefaultTheme;// it seems like this creates a new ghost sidebar that isn't useful at all.// need access to the Layout component's sidebar, but that's not exposed.const {isOpen: isSidebarOpen,open: openSidebar,close: closeSidebar,sidebar: sidebar,sidebarGroups: sidebarGroups,} =useSidebar();const touchStart = { x: 0, y: 0 };const onTouchStart = (e:TouchEvent):void=> {console.log("touch started");touchStart.x=e.changedTouches[0].clientX;touchStart.y=e.changedTouches[0].clientY;};const onTouchEnd = (e:TouchEvent):void=> {console.log("touch ended");const dx =e.changedTouches[0].clientX-touchStart.x;const dy =e.changedTouches[0].clientY-touchStart.y;if (Math.abs(dx) >Math.abs(dy) &&Math.abs(dx) >40) {if (dx>0&&touchStart.x<=80) {console.log("opening sidebar");openSidebar(); } else {console.log("closing sidebar");closeSidebar(); } }};</script>
<template>
<Layout @touchstart="onTouchStart" @touchend="onTouchEnd">
<template #layout-top>
<!-- this is just to show that isSidebarOpen does not correspond to the actual state of the sidebar -->
<h1>{{ isSidebarOpen ?"OPEN":"CLOSED" }}</h1>
</template>
</Layout>
</template>
As you will see, I can swipe and trigger the console.log correctly, but the sidebar does not open. When I swipe, isSidebarOpen is set to true, but the sidebar doesn't show, which makes me think, useSidebar is not connected to the actual sidebar :/
Although not as minimal, this solution is implemented here if you want a checkout-ready attempt (Joelius300/werewolf-guide@59a78d1).
Completely new layout without using the default-theme one
This also doesn't work, but in a different way. It doesn't display any content and in the browser I get the following warning: [Vue warn]: Component is missing template or render function:. Despite that, swiping left to right actually works great and prints opening sidebar in the console, it just doesn't open anything because the page is blank.
Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.
The text was updated successfully, but these errors were encountered:
Joelius300
changed the title
Open Sidebar with touch navigation (swipe) [default-theme]
Open Sidebar with touch navigation (swipe) [default-theme] (bug in useSidebar?)
Nov 1, 2024
Joelius300
changed the title
Open Sidebar with touch navigation (swipe) [default-theme] (bug in useSidebar?)
Open sidebar with touch navigation (swipe) [default-theme] (bug in useSidebar?)
Nov 1, 2024
Is your feature request related to a problem? Please describe.
In the VuePress default theme, you can swipe left-to-right to open the sidebar. See for example on https://vuepress.vuejs.org/ (if on desktop, emulate phone mode in dev tools).
Vitepress' default theme does not have that feature, even though it would be nice. More importantly, I could not figure out how to use
useSidebar
to implement it myself (see below).Describe the solution you'd like
Add this small feature (potentially as an option) to the default theme and/or enable users of VitePress to implement such thnigs themselves by extending the default theme.
Describe alternatives you've considered
Here are some approaches I attempted, none work. The code for the swipe logic is adapted from VuePress' default-theme and works great, the problem seems to be with my use of
useSidebar
.Extending default theme with custom layout
As you will see, I can swipe and trigger the console.log correctly, but the sidebar does not open. When I swipe,
isSidebarOpen
is set to true, but the sidebar doesn't show, which makes me think,useSidebar
is not connected to the actual sidebar :/Although not as minimal, this solution is implemented here if you want a checkout-ready attempt (Joelius300/werewolf-guide@59a78d1).
Completely new layout without using the default-theme one
I copied the code from https://github.com/vuejs/vitepress/blob/2b3cd95ab112ffce3a168b41c8cca1446d3fb920/src/client/theme-default/Layout.vue and adjusted it to work with imports from the vitepress package instead of internal ones (also had to copy
useCloseSidebarOnEscape
.This also doesn't work, but in a different way. It doesn't display any content and in the browser I get the following warning:
[Vue warn]: Component is missing template or render function:
. Despite that, swiping left to right actually works great and printsopening sidebar
in the console, it just doesn't open anything because the page is blank.This implementation can also be found here: Joelius300/werewolf-guide@f745d8c.
In general, you'll find multiple different attempts in this branch: https://github.com/Joelius300/werewolf-guide/commits/swipe-sidebar
Taking a ref to the layout and accessing
openSidebar
from thereDoesn't work because
openSidebar
is not exposed withdefineExpose
(see https://vuejs.org/guide/essentials/template-refs.html#ref-on-component). This would also tightly couple the two and I don't think is a good idea.Additional context
I am more than happy to learn how to correctly use
useSidebar
to implement this without adding it to the default theme.Validations
The text was updated successfully, but these errors were encountered: