Skip to content

Commit

Permalink
Fixed #2908 - Improve Panel implementation for Accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Aug 31, 2022
1 parent e917116 commit c22d395
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
6 changes: 6 additions & 0 deletions api-generator/components/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const PanelProps = [
type: "boolean",
default: "null",
description: "Defines the initial state of panel content."
},
{
name: "toggleButtonProps",
type: "string",
default: "null",
description: "Uses to pass the custom value to read for the anchor inside the component."
}
];

Expand Down
4 changes: 4 additions & 0 deletions src/components/panel/Panel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export interface PanelProps {
* Defines the initial state of panel content.
*/
collapsed?: boolean;
/**
* Uses to pass the custom value to read for the button inside the component.
*/
toggleButtonProps?: string | undefined;
}

export interface PanelSlots {
Expand Down
13 changes: 10 additions & 3 deletions src/components/panel/Panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</slot>
<div class="p-panel-icons">
<slot name="icons"></slot>
<button v-if="toggleable" class="p-panel-header-icon p-panel-toggler p-link" @click="toggle" type="button"
:id="ariaId + '_header'" :aria-controls="ariaId + '_content'" :aria-expanded="!d_collapsed" v-ripple>
<button type="button" role="button" v-if="toggleable" class="p-panel-header-icon p-panel-toggler p-link" :id="ariaId + '_header'" :aria-label="toggleButtonProps||header" :aria-controls="ariaId + '_content'" :aria-expanded="!d_collapsed"
@click="toggle" @keydown="onKeyDown" v-ripple>
<span :class="{'pi pi-minus': !d_collapsed, 'pi pi-plus': d_collapsed}"></span>
</button>
</div>
Expand All @@ -32,7 +32,8 @@ export default {
props: {
header: String,
toggleable: Boolean,
collapsed: Boolean
collapsed: Boolean,
toggleButtonProps: String
},
data() {
return {
Expand All @@ -52,6 +53,12 @@ export default {
originalEvent: event,
value: this.d_collapsed
});
},
onKeyDown(event) {
if (event.code === 'Enter' || event.code === 'Space') {
this.toggle(event);
event.preventDefault();
}
}
},
computed: {
Expand Down
44 changes: 44 additions & 0 deletions src/views/panel/PanelDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ import Panel from 'primevue/panel';
<td>boolean</td>
<td>null</td>
<td>Defines the initial state of panel content.</td>
</tr>
<tr>
<td>toggleButtonProps</td>
<td>string</td>
<td>null</td>
<td>Uses to pass the custom value to read for the button inside the component.</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -201,6 +207,44 @@ import Panel from 'primevue/panel';
</table>
</div>

<h5>Accessibility</h5>
<DevelopmentSection>
<h6>Screen Reader</h6>
<p>Toggleable panels use a content toggle button at the header that has <i>aria-controls</i> to define the id of the content section along with <i>aria-expanded</i> for the visibility state. The value to read the button
defaults to the value of the <i>header</i> property and can be customized by defining an <i>aria-label</i> or <i>aria-labelledby</i> via the <i>toggleButtonProps</i> property.</p>
<p>The content uses <i>region</i>, defines an id that matches the <i>aria-controls</i> of the content toggle button and <i>aria-labelledby</i> referring to the id of the header.</p>

<h6>Content Toggle Button Keyboard Support</h6>
<div class="doc-tablewrapper">
<table class="doc-table">
<thead>
<tr>
<th>Key</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td><i>tab</i></td>
<td>Moves focus to the next the focusable element in the page tab sequence.</td>
</tr>
<tr>
<td><i>shift</i> + <i>tab</i></td>
<td>Moves focus to the previous the focusable element in the page tab sequence.</td>
</tr>
<tr>
<td><i>enter</i></td>
<td>Toggles the visibility of the content.</td>
</tr>
<tr>
<td><i>space</i></td>
<td>Toggles the visibility of the content.</td>
</tr>
</tbody>
</table>
</div>
</DevelopmentSection>

<h5>Dependencies</h5>
<p>None.</p>
</AppDoc>
Expand Down

0 comments on commit c22d395

Please sign in to comment.