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

Breadcrumb accessibility improvment #2976

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
4 changes: 2 additions & 2 deletions src/components/breadcrumb/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<nav class="p-breadcrumb p-component" aria-label="Breadcrumb">
<nav class="p-breadcrumb p-component" role="navigation">
<ul>
<BreadcrumbItem v-if="home" :item="home" class="p-breadcrumb-home" :template="$slots.item" :exact="exact" />
<template v-for="item of model" :key="item.label">
<li class="p-breadcrumb-chevron pi pi-chevron-right"></li>
<li class="p-breadcrumb-chevron pi pi-chevron-right" :aria-hidden="true"></li>
<BreadcrumbItem :item="item" :template="$slots.item" :exact="exact" />
</template>
</ul>
Expand Down
11 changes: 9 additions & 2 deletions src/components/breadcrumb/BreadcrumbItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
<li v-if="visible()" :class="containerClass(item)">
<template v-if="!template">
<router-link v-if="item.to" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
<a :href="href" :class="linkClass({ isActive, isExactActive })" @click="onClick($event, navigate)">
<a :href="href" :class="linkClass({ isActive, isExactActive })" @click="onClick($event, navigate)" :aria-current="isCurrentUrl()">
<span v-if="item.icon" :class="iconClass"></span>
<span v-if="item.label" class="p-menuitem-text">{{ label() }}</span>
</a>
</router-link>
<a v-else :href="item.url || '#'" :class="linkClass()" @click="onClick" :target="item.target">
<a v-else :href="item.url || '#'" :class="linkClass()" @click="onClick" :target="item.target" :aria-current="isCurrentUrl()">
<span v-if="item.icon" :class="iconClass"></span>
<span v-if="item.label" class="p-menuitem-text">{{ label() }}</span>
</a>
</template>

<component v-else :is="template" :item="item"></component>
</li>
</template>
Expand Down Expand Up @@ -57,6 +58,12 @@ export default {
},
label() {
return typeof this.item.label === 'function' ? this.item.label() : this.item.label;
},
isCurrentUrl() {
const { to, url } = this.item;
const lastPath = `/${window.location.href.split('/').pop()}`;
return to === lastPath || url === lastPath ? 'page' : false;
}
},
computed: {
Expand Down
21 changes: 18 additions & 3 deletions src/views/breadcrumb/BreadcrumbDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ export default {

<h5>Dependencies</h5>
<p>None.</p>

<h5>Accessibility</h5>
<DevelopmentSection>
<h6>Screen Reader</h6>
<p>
Breadcrumb uses the <i>nav</i> element and since any attribute is passed to the root implicitly <i>aria-labelledby</i> or <i>aria-label</i> can be used to describe the component. Inside an ordered list is used where the list item
separators have <i>aria-hidden</i> to be able to ignored by the screen readers. If the last link represents the current route, <i>aria-current</i> is added with "page" as the value.
</p>

<h6>Keyboard Support</h6>
<p>No special keyboard interaction is needed, all menuitems are focusable based on the page tab sequence.</p>
</DevelopmentSection>

<h5>Dependencies</h5>
<p>None.</p>
</AppDoc>
</template>

Expand All @@ -172,7 +187,7 @@ export default {
data() {
return {
home: {
icon: 'pi pi-home',
icon: 'pi pi-home',
to: '/',
},
items: [
Expand Down Expand Up @@ -203,7 +218,7 @@ import { ref } from 'vue';
export default {
setup() {
const home = ref({
icon: 'pi pi-home',
icon: 'pi pi-home',
to: '/',
});
const items = ref([
Expand Down Expand Up @@ -235,7 +250,7 @@ export default {
const App = {
setup() {
const home = ref({
icon: 'pi pi-home',
icon: 'pi pi-home',
to: '/',
});
const items = ref([
Expand Down