Skip to content

Commit ceb0fa9

Browse files
authoredAug 23, 2020
fix($theme-default): overlap navbar dropdown menus (fix #2227) (#2365)
1 parent d4d0380 commit ceb0fa9

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed
 

‎packages/@vuepress/theme-default/__tests__/components/__snapshots__/DropdownLink.spec.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`DropdownLink renders dropdown link. 1`] = `
4-
<div class="dropdown-wrapper"><button type="button" aria-label="Learn More Select" class="dropdown-title"><span class="title">Learn More</span> <span class="arrow right"></span></button>
4+
<div class="dropdown-wrapper"><button type="button" aria-label="Learn More Select" class="dropdown-title"><span class="title">Learn More</span> <span class="arrow down"></span></button> <button type="button" aria-label="Learn More Select" class="mobile-dropdown-title"><span class="title">Learn More</span> <span class="arrow right"></span></button>
55
<ul class="nav-dropdown" style="display: none;" name="dropdown">
66
<li class="dropdown-item">
77
<!----> <a class="nav-link">

‎packages/@vuepress/theme-default/components/DropdownLink.vue

+32-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
class="dropdown-title"
88
type="button"
99
:aria-label="dropdownAriaLabel"
10+
@click="handleDropdown"
11+
>
12+
<span class="title">{{ item.text }}</span>
13+
<span
14+
class="arrow down"
15+
/>
16+
</button>
17+
<button
18+
class="mobile-dropdown-title"
19+
type="button"
20+
:aria-label="dropdownAriaLabel"
1021
@click="setOpen(!open)"
1122
>
1223
<span class="title">{{ item.text }}</span>
@@ -105,6 +116,17 @@ export default {
105116
106117
isLastItemOfArray (item, array) {
107118
return last(array) === item
119+
},
120+
121+
/**
122+
* Open the dropdown when user tab and click from keyboard.
123+
*
124+
* Use event.detail to detect tab and click from keyboard. Ref: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
125+
* The Tab + Click is UIEvent > KeyboardEvent, so the detail is 0.
126+
*/
127+
handleDropdown () {
128+
const isTriggerByTab = event.detail === 0
129+
if (isTriggerByTab) this.setOpen(!this.open)
108130
}
109131
}
110132
}
@@ -130,6 +152,13 @@ export default {
130152
vertical-align middle
131153
margin-top -1px
132154
margin-left 0.4rem
155+
.mobile-dropdown-title
156+
@extends .dropdown-title
Has conversations. Original line has conversations.
157+
display none
158+
font-weight 600
159+
font-size inherit
160+
&:hover
161+
color $accentColor
133162
.nav-dropdown
134163
.dropdown-item
135164
color inherit
@@ -175,10 +204,9 @@ export default {
175204
&.open .dropdown-title
176205
margin-bottom 0.5rem
177206
.dropdown-title
178-
font-weight 600
179-
font-size inherit
180-
&:hover
181-
color $accentColor
207+
display: none
208+
.mobile-dropdown-title
209+
display: block
182210
.nav-dropdown
183211
transition height .1s ease-out
184212
overflow hidden
@@ -203,12 +231,6 @@ export default {
203231
display block !important
204232
&.open:blur
205233
display none
206-
.dropdown-title .arrow
207-
// make the arrow always down at desktop
208-
border-left 4px solid transparent
209-
border-right 4px solid transparent
210-
border-top 6px solid $arrowBgColor
211-
border-bottom 0
212234
.nav-dropdown
213235
display none
214236
// Avoid height shaked by clicking

0 commit comments

Comments
 (0)
Please sign in to comment.