Skip to content

Commit

Permalink
feat(sidebar): close when navigating
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Oct 19, 2020
1 parent 6891092 commit 2094d53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/client/theme-default/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</template>
</SideBar>
</aside>
<!-- TODO: make this button accessible -->
<div
class="sidebar-mask"
:class="{ 'sidebar-open': open }"
Expand All @@ -38,11 +39,12 @@
</template>

<script>
import { ref } from 'vue'
import { ref, watch } from 'vue'
import NavBar from './components/NavBar.vue'
import ToggleSideBarButton from './components/ToggleSideBarButton.vue'
import SideBar from './components/SideBar.vue'
import Page from './components/Page.vue'
import { useRoute } from 'vitepress'
export default {
components: {
Expand All @@ -54,11 +56,18 @@ export default {
setup() {
const open = ref(false)
const route = useRoute()
const toggleSidebar = (to) => {
open.value = typeof to === 'boolean' ? to : !open.value
}
const hideSidebar = toggleSidebar.bind(null, false)
// close the sidebar when navigating to a different location
watch(route, hideSidebar)
// TODO: route only changes when the pathname changes
// listening to hashchange does nothing because it's prevented in router
return { open, toggleSidebar }
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/theme-default/components/SideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
.sidebar-items .sidebar-link {
padding: .35rem 1rem .35rem 2rem;
padding: 0.35rem 1rem 0.35rem 2rem;
line-height: 1.4;
font-size: 0.95em;
font-weight: 400;
Expand All @@ -75,16 +75,16 @@
.sidebar-link {
display: block;
margin: 0;
border-left: .25rem solid transparent;
padding: .35rem 1.5rem .35rem 1.25rem;
border-left: 0.25rem solid transparent;
padding: 0.35rem 1.5rem 0.35rem 1.25rem;
line-height: 1.7;
font-size: 1.05em;
font-weight: 700;
color: var(--text-color);
}
a.sidebar-link {
transition: color .15s ease;
transition: color 0.15s ease;
}
a.sidebar-link:hover {
Expand Down

0 comments on commit 2094d53

Please sign in to comment.