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

Improve navbar accessibility #951

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. The format
### Fixed

- Fixed disappearing navigation header for mobile users.
- Added missing aria roles and attributes for navbar components.

### Breaking changes

Expand Down
16 changes: 12 additions & 4 deletions src/components/Navigation/SiteHeader.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<header class="site-navigation">
<nav class="nav-bar site-navigation__menubar">
<nav class="nav-bar site-navigation__menubar" role="menubar">
<!-- Site menu -->
<nav-menu class="site-menu">
<nav-menu-item dropdown>
<nav-menu-item :aria="{ label: siteMenuLabel }" dropdown>
<template #text>
<pkt-icon class="nav-menu-item__icon" name="bullseye" />
<span class="pkt-show-tablet-up">{{ siteMenuLabel }}</span>
Expand All @@ -23,6 +23,7 @@
:class="['item-menu__item', `item-menu__item--${itemMenuTab.pull || 'left'}`]"
:route="itemMenuTab.route"
:active="itemMenuTab.active"
:aria="{ label: itemMenuTab.label || itemMenuTab.tooltip }"
>
<template #text>
<pkt-icon
Expand All @@ -42,13 +43,20 @@

<!-- User menu -->
<nav-menu class="user-menu">
<nav-menu-item v-if="user" ref="userMenu" v-slot="{ close }" icon="user" dropdown>
<nav-menu-item
v-if="user"
ref="userMenu"
v-slot="{ close }"
:aria="{ label: $t('user.myProfile') }"
icon="user"
dropdown
>
<user-menu-dropdown :id="user.id" :handle-navigation="close" />
</nav-menu-item>
</nav-menu>
</nav>

<nav v-if="showToolbar" class="nav-bar site-navigation__toolbar">
<nav v-if="showToolbar" class="nav-bar site-navigation__toolbar" role="menubar">
<period-selector-menu />
<view-toggle />
</nav>
Expand Down
1 change: 1 addition & 0 deletions src/components/Navigation/navbar/NavMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{ 'nav-menu--tabs': tabs },
{ 'nav-menu--toggles': toggles },
]"
role="menu"
>
<slot />
</ul>
Expand Down
25 changes: 25 additions & 0 deletions src/components/Navigation/navbar/NavMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
{ 'nav-menu-item--dropdown': dropdown },
{ 'nav-menu-item--open': isOpen },
]"
role="none"
>
<router-link
v-if="route"
v-slot="{ href, navigate, isExactActive }"
:to="route"
:role="role"
custom
>
<a
Expand All @@ -20,6 +22,7 @@
{ 'nav-menu-item__inner--icon-only': icon && !text },
{ 'nav-menu-item__inner--active': active || isExactActive },
]"
v-bind="ariaAttrs"
@click="activate($event, navigate)"
>
<slot name="text">
Expand All @@ -35,7 +38,11 @@
'nav-menu-item__inner',
{ 'nav-menu-item__inner--active': active || isOpen },
]"
:role="role"
tabindex="0"
:aria-haspopup="dropdown"
:aria-expanded="isOpen"
v-bind="ariaAttrs"
@click="activate"
@keyup.enter="activate"
>
Expand Down Expand Up @@ -92,12 +99,30 @@ export default {
required: false,
default: false,
},
role: {
type: String,
required: false,
default: 'menuitem',
},
aria: {
type: Object,
required: false,
default: null,
},
},

data: () => ({
isOpen: false,
}),

computed: {
ariaAttrs() {
return this.aria
? Object.fromEntries(Object.entries(this.aria).map(([k, v]) => [`aria-${k}`, v]))
: null;
},
},

watch: {
isOpen() {
this.$emit('open');
Expand Down
5 changes: 5 additions & 0 deletions src/components/Navigation/toolbar/ViewToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
v-for="view in views"
:key="view.key"
v-tooltip="$t('tooltip.changeView', { view: view.name })"
:aria="{
label: $t('tooltip.changeView', { view: view.name }),
checked: view.active,
}"
role="menuitemradio"
v-bind="view"
/>
</nav-menu>
Expand Down