Skip to content

fix($theme-default): Make navbar dropdown links accessible #1837

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

Merged
merged 18 commits into from
Sep 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('DropdownLink', () => {
stubs: {
'router-link': RouterLinkStub
},
propsData: { item }
propsData: { item, dropdownName: 'Languages' }
})
expect(wrapper.html()).toMatchSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DropdownLink renders dropdown link. 1`] = `
<div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
<div class="dropdown-wrapper"><a aria-label="Languages" class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
<ul class="nav-dropdown" style="display: none;" name="dropdown">
<li class="dropdown-item">
<!----> <a class="nav-link">Guide</a></li>
Expand Down
5 changes: 5 additions & 0 deletions packages/@vuepress/theme-default/components/DropdownLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
>
<a

Choose a reason for hiding this comment

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

The NavLink element should be only when it acts as a link (e.g. has a valid href value). If it's acting as a trigger to open a dropdown navigation, it should be a . This should probably remove the need to set an explicit tabindex ( without href is not focusable, but is focusable, at least on Chrome).

class="dropdown-title"
:aria-label="dropdownName"
@click="toggle"
>
<span class="title">{{ item.text }}</span>
Expand Down Expand Up @@ -65,6 +66,10 @@ export default {
props: {
item: {
required: true
},
dropdownName: {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
}
},

Expand Down
12 changes: 11 additions & 1 deletion packages/@vuepress/theme-default/components/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
<!-- user links -->
<div
class="nav-item"
v-for="item in userLinks"
v-for="(item, index) in userLinks"
:tabindex="tabIndexStart + index"
:key="item.link"
>
<DropdownLink
v-if="item.type === 'links'"
:item="item"
dropdownName="Select Dropdown"
/>
<NavLink
v-else
Expand All @@ -25,6 +27,7 @@
:href="repoLink"
class="repo-link"
target="_blank"
:tabindex="tabIndexStart + userLinks.length"
rel="noopener noreferrer"
>
{{ repoLabel }}
Expand All @@ -41,6 +44,13 @@ import NavLink from '@theme/components/NavLink.vue'
export default {
components: { NavLink, DropdownLink },

props: {
tabIndexStart: {
default: 3,
type: Number
}
},

computed: {
userNav () {
return this.$themeLocaleConfig.nav || this.$site.themeConfig.nav || []
Expand Down
4 changes: 3 additions & 1 deletion packages/@vuepress/theme-default/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<router-link
:to="$localePath"
class="home-link"
tabindex="1"
>
<img
class="logo"
Expand All @@ -28,9 +29,10 @@
>
<AlgoliaSearchBox
v-if="isAlgoliaSearch"
tabindex="2"
:options="algolia"
/>
<SearchBox v-else-if="$site.themeConfig.search !== false && $page.frontmatter.search !== false"/>
<SearchBox tabindex="1" v-else-if="$site.themeConfig.search !== false && $page.frontmatter.search !== false"/>
<NavLinks class="can-hide"/>
</div>
</header>
Expand Down