Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($theme-default): navbar dropdown issue (fix #2349) #2339

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions packages/@vuepress/theme-default/components/DropdownLink.vue
Expand Up @@ -2,12 +2,13 @@
<div
class="dropdown-wrapper"
:class="{ open }"
@focusout="close(true)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The close method will only really close when the arg is false or the device is mobile, and it will never happen here.

>
<button
class="dropdown-title"
type="button"
:aria-label="dropdownAriaLabel"
@click="setOpen(!open)"
@click="toggle"
>
<span class="title">{{ item.text }}</span>
<span
Expand Down Expand Up @@ -44,7 +45,7 @@
@focusout="
isLastItemOfArray(childSubItem, subItem.items) &&
isLastItemOfArray(subItem, item.items) &&
setOpen(false)
close()
"
/>
</li>
Expand All @@ -53,7 +54,7 @@
<NavLink
v-else
:item="subItem"
@focusout="isLastItemOfArray(subItem, item.items) && setOpen(false)"
@focusout="isLastItemOfArray(subItem, item.items) && close()"
/>
</li>
</ul>
Expand All @@ -75,13 +76,18 @@ export default {
},

props: {
inSidebar: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll only display in sidebar if the device is mobile, so it seems that you only need one of them (inSidebar or isMobile).

type: Boolean,
default: false
},
item: {
required: true
}
},

data () {
return {
isMobile: false,
open: false
}
},
Expand All @@ -98,9 +104,19 @@ export default {
}
},

mounted () {
this.isMobile = 'ontouchstart' in document.documentElement
},

methods: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods isn't intuitive. The close won't really close, and what isButton? I believe it's here to detect whether users use keyboard to click the button, right?

setOpen (value) {
this.open = value
toggle (event) {
const isButton = event.detail === 0

if (this.inSidebar || this.isMobile || isButton) this.open = !this.open
},

close (judge) {
if (!judge || (judge && this.isMobile)) this.open = false
},

isLastItemOfArray (item, array) {
Expand Down
8 changes: 8 additions & 0 deletions packages/@vuepress/theme-default/components/NavLinks.vue
Expand Up @@ -11,6 +11,7 @@
>
<DropdownLink
v-if="item.type === 'links'"
:in-sidebar="inSidebar"
:item="item"
/>
<NavLink
Expand Down Expand Up @@ -46,6 +47,13 @@ export default {
DropdownLink
},

props: {
inSidebar: {
type: Boolean,
default: false
}
},

computed: {
userNav () {
return this.$themeLocaleConfig.nav || this.$site.themeConfig.nav || []
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/theme-default/components/Sidebar.vue
@@ -1,6 +1,6 @@
<template>
<aside class="sidebar">
<NavLinks />
<NavLinks :in-sidebar="true" />

<slot name="top" />

Expand Down