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 DataView implementation for accessibility #3311

Merged
merged 6 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 1 deletion src/components/config/PrimeVue.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ const defaultOptions = {
filterConstraint: 'Filter Constraint',
editRow: 'Row Edit',
saveEdit: 'Save Edit',
cancelEdit: 'Cancel Edit'
cancelEdit: 'Cancel Edit',
listView: 'List View',
gridView: 'Grid View'
}
},
filterMatchModeOptions: {
Expand Down
5 changes: 4 additions & 1 deletion src/components/dataview/DataView.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils';
import PrimeVue from 'primevue/config';
import DataView from './DataView.vue';

import PrimeVue from 'primevue/config';
describe('DataView.vue', () => {
it('should exist', () => {
const wrapper = mount(DataView, {
Expand Down Expand Up @@ -75,6 +75,9 @@ describe('DataView.vue', () => {
</div>
</template>
`
},
global: {
plugins: [PrimeVue]
}
});

Expand Down
13 changes: 12 additions & 1 deletion src/components/dataview/DataView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="containerClass">
<div :class="containerClass" :aria-label="getAriaLabel">
<div v-if="$slots.header" class="p-dataview-header">
<slot name="header"></slot>
</div>
Expand Down Expand Up @@ -235,6 +235,17 @@ export default {
} else {
return null;
}
},
getAriaLabel() {
const ariaLabels = this.$primevue.config.locale.aria;

if (this.layout === 'list') {
return ariaLabels ? ariaLabels.listView : undefined;
} else if (this.layout === 'grid') {
return ariaLabels ? ariaLabels.gridView : undefined;
}

return null;
}
},
components: {
Expand Down
38 changes: 37 additions & 1 deletion src/views/dataview/DataViewDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<pre v-code.script><code>
import DataView from 'primevue/dataview';

</code></pre>

<h5>Import via CDN</h5>
Expand Down Expand Up @@ -468,6 +468,42 @@ export default {
</table>
</div>

<h5>Accessibility</h5>

<h6>Screen Reader</h6>
<p>
The container element that wraps the layout options buttons has a <i>group</i> role whereas each button element uses <i>button</i> role and <i>aria-pressed</i> is updated depending on selection state. Values to describe the buttons are
derived from the <i>aria.listView</i> and <i>aria.gridView</i> properties of the <Link href="/locale">locale</Link> API respectively.
</p>

<p>Refer to <Link href="/paginator">paginator</Link> accessibility documentation for the paginator of the component.</p>

<h6>Keyboard Support</h6>
<div className="doc-tablewrapper">
<table className="doc-table">
<thead>
<tr>
<th>Key</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<i>tab</i>
</td>
<td>Moves focus to the buttons.</td>
</tr>
<tr>
<td>
<i>space</i>
</td>
<td>Toggles the checked state of a button.</td>
</tr>
</tbody>
</table>
</div>

<h5>Dependencies</h5>
<p>PrimeFlex</p>
</AppDoc>
Expand Down
4 changes: 3 additions & 1 deletion src/views/locale/LocaleDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ locale: {
filterConstraint: 'Filter Constraint',
editRow: 'Row Edit',
saveEdit: 'Save Edit',
cancelEdit: 'Cancel Edit'
cancelEdit: 'Cancel Edit',
listView: 'List View',
gridView: 'Grid View'
}
}

Expand Down