Skip to content

Commit

Permalink
enh(a11y): Add nav to header menu
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Sep 6, 2023
1 parent 8971a7e commit ed36794
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/components/NcHeaderMenu/NcHeaderMenu.vue
Expand Up @@ -64,8 +64,10 @@ export default {
</docs>

<template>
<div :id="id"
<component :is="wrapperTag"
:id="id"
v-click-outside="clickOutsideConfig"
:aria-label="isNav ? navAriaLabel : null"
:class="{ 'header-menu--opened': opened }"
class="header-menu">
<!-- Open trigger icon -->
Expand All @@ -87,14 +89,13 @@ export default {
<!-- Menu opened content -->
<div v-show="opened"
:id="`header-menu-${id}`"
class="header-menu__wrapper"
role="menu">
class="header-menu__wrapper">
<div ref="content" class="header-menu__content">
<!-- @slot Main content -->
<slot />
</div>
</div>
</div>
</component>
</template>

<script>
Expand Down Expand Up @@ -139,6 +140,24 @@ export default {
type: Boolean,
default: false,
},
/**
* Pass `true` if the header menu is used for website navigation
*
* The wrapper tag will be set to `nav`
*/
isNav: {
type: Boolean,
default: false,
},
/**
* aria-label attribute of the `nav` element
*/
navAriaLabel: {
type: String,
default: null,
},
},
emits: [
Expand All @@ -159,6 +178,10 @@ export default {
},
computed: {
wrapperTag() {
return this.isNav ? 'nav' : 'div'
},
clickOutsideConfig() {
return [
this.closeMenu,
Expand Down Expand Up @@ -359,5 +382,4 @@ $externalMargin: 8px;
}
}
}
</style>

0 comments on commit ed36794

Please sign in to comment.