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): Make navbar dropdown links accessible #1837

Merged
merged 18 commits into from
Sep 15, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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', tabIndex: 8 }
})
expect(wrapper.html()).toMatchSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// 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" tabindex="8" 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>
<!----> <a class="nav-link" tabindex="8">Guide</a></li>

Choose a reason for hiding this comment

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

We should try to avoid the use of positive values for tabindex if possible:
https://webaim.org/techniques/keyboard/tabindex

<li class="dropdown-item">
<!----> <a class="nav-link">Config Reference</a></li>
<!----> <a class="nav-link" tabindex="8">Config Reference</a></li>
</ul>
</div>
`;
16 changes: 14 additions & 2 deletions packages/@vuepress/theme-default/components/DropdownLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
>
<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"
:tabindex="tabIndex"
>
<span class="title">{{ item.text }}</span>
<span
Expand Down Expand Up @@ -35,12 +37,13 @@
:key="childSubItem.link"
v-for="childSubItem in subItem.items"
>
<NavLink :item="childSubItem"/>
<NavLink :tabindex="tabIndex" :item="childSubItem"/>
</li>
</ul>

<NavLink
v-else
:tabindex="tabIndex"
:item="subItem"
/>
</li>
Expand All @@ -65,6 +68,14 @@ 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
},
tabIndex: {
default: 0,
type: Number
}
},

Expand Down Expand Up @@ -149,7 +160,8 @@ export default {
@media (min-width: $MQMobile)
.dropdown-wrapper
height 1.8rem
&:hover .nav-dropdown
&:hover .nav-dropdown,
&:focus-within .nav-dropdown

Choose a reason for hiding this comment

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

Opening the submenu on focus-within works ok, but it could be annoying if there's a navbar with many long submenus (i.e. you'd have to tab through every single item to get past the navbar). Adding a skip navigation link could help with that (and probably should also be added regardless), but a keyboard user would still have to tab through every submenu item on the way to the one they actually want.

The Adobe Mega Menu is a good example of the expected keyboard interactions and aria markup:

Copy link
Collaborator

Choose a reason for hiding this comment

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

thx for your explanation @missmatsuko

Copy link
Contributor Author

@edisdev edisdev Sep 8, 2019

Choose a reason for hiding this comment

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

@missmatsuko Thank you for comment and review :) You are right, Maybe it can make to focus submenus when key press the enter. Or, can be added focusable property to config file. and i will make tabindex="0" for focusable items . What do you think about this ?

Choose a reason for hiding this comment

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

I think there doesn't need to be an tabindex attribute at all. Can the link element be changed to a if it has children submenu items, and an anchor if it has an href?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made testing when I remove tabindex, element can not focusable in safari and firefox. @missmatsuko

// override the inline style.
display block !important
.dropdown-title .arrow
Expand Down
13 changes: 12 additions & 1 deletion packages/@vuepress/theme-default/components/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
<!-- user links -->
<div
class="nav-item"
v-for="item in userLinks"
v-for="(item, index) in userLinks"
:key="item.link"
>
<DropdownLink
v-if="item.type === 'links'"
:item="item"
:tab-index="tabIndexStart + index"
dropdownName="Select Dropdown"
/>
<NavLink
v-else
:tabindex="tabIndexStart + index"
:item="item"
/>
</div>
Expand All @@ -25,6 +28,7 @@
:href="repoLink"
class="repo-link"
target="_blank"
:tabindex="tabIndexStart + userLinks.length"
rel="noopener noreferrer"
>
{{ repoLabel }}
Expand All @@ -41,6 +45,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