-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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): Make navbar dropdown links accessible #1837
Changes from 10 commits
311f11f
44462b6
3593b4b
e996d18
510be5b
380911d
fd30a60
8bd733f
1b38f36
a5a66f1
0a27789
96b1287
c67010e
e84b6c6
6da2e5f
842157d
371af79
0ef66cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,18 @@ | |
class="dropdown-wrapper" | ||
:class="{ open }" | ||
> | ||
<a | ||
<button | ||
class="dropdown-title" | ||
type="button" | ||
:aria-label="dropdownName" | ||
@click="toggle" | ||
> | ||
<span class="title">{{ item.text }}</span> | ||
<span | ||
class="arrow" | ||
:class="open ? 'down' : 'right'" | ||
></span> | ||
</a> | ||
</button> | ||
|
||
<DropdownTransition> | ||
<ul | ||
|
@@ -33,14 +35,17 @@ | |
<li | ||
class="dropdown-subitem" | ||
:key="childSubItem.link" | ||
v-for="childSubItem in subItem.items" | ||
v-for="(childSubItem, subIndex) in subItem.items" | ||
> | ||
<NavLink :item="childSubItem"/> | ||
<NavLink | ||
@keypressTab="focusoutDropdown((index + 2) * (subIndex + 1))" | ||
:item="childSubItem"/> | ||
</li> | ||
</ul> | ||
|
||
<NavLink | ||
v-else | ||
@keypressTab="focusoutDropdown(index + 1)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that |
||
:item="subItem" | ||
/> | ||
</li> | ||
|
@@ -65,12 +70,34 @@ export default { | |
props: { | ||
item: { | ||
required: true | ||
}, | ||
dropdownName: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why using a props for the dropdown name? Why don't we just keep it as a local variable in the component? Btw I think we should consider a way to make this label customizable. The user might want to display different labels depending on the current selected language. This should be a default theme local. Could you add this feature and update the documentation? |
||
default: 'Dropdown', | ||
type: String | ||
} | ||
}, | ||
|
||
computed: { | ||
AllItemsCount () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be named with a lower-case |
||
return this.item.items.reduce((totalCount, item) => { | ||
return item.items ? totalCount + item.items.length : totalCount + 1 | ||
}, 0) | ||
} | ||
}, | ||
|
||
methods: { | ||
toggle () { | ||
this.open = !this.open | ||
}, | ||
|
||
focusoutDropdown (index) { | ||
if (this.AllItemsCount === index) this.open = false | ||
} | ||
}, | ||
|
||
watch: { | ||
$route () { | ||
this.open = false | ||
} | ||
} | ||
} | ||
|
@@ -81,6 +108,11 @@ export default { | |
cursor pointer | ||
.dropdown-title | ||
display block | ||
font-size 0.9rem | ||
background transparent | ||
border none | ||
font-weight 500 | ||
color $textColor | ||
&:hover | ||
border-color transparent | ||
.arrow | ||
|
@@ -149,9 +181,12 @@ export default { | |
@media (min-width: $MQMobile) | ||
.dropdown-wrapper | ||
height 1.8rem | ||
&:hover .nav-dropdown | ||
&:hover .nav-dropdown, | ||
&.open .nav-dropdown | ||
// override the inline style. | ||
display block !important | ||
&.open:blur | ||
display none | ||
.dropdown-title .arrow | ||
// make the arrow always down at desktop | ||
border-left 4px solid transparent | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
<router-link | ||
class="nav-link" | ||
:to="link" | ||
@keyup.tab.native="keypressTab" | ||
v-if="!isExternal(link)" | ||
:exact="exact" | ||
>{{ item.text }}</router-link> | ||
<a | ||
v-else | ||
:href="link" | ||
@keyup.tab.prevent="keypressTab" | ||
class="nav-link external" | ||
:target="isMailto(link) || isTel(link) ? null : '_blank'" | ||
:rel="isMailto(link) || isTel(link) ? null : 'noopener noreferrer'" | ||
|
@@ -43,7 +45,10 @@ export default { | |
methods: { | ||
isExternal, | ||
isMailto, | ||
isTel | ||
isTel, | ||
keypressTab () { | ||
this.$emit('keypressTab') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you rename this event |
||
} | ||
} | ||
} | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the
+ 2
? Could you explain? Why not just+ 1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, There was a bug here. I resolved this. 👍