From c22d395a9c60a6ed7f65adccccf662a70a2a6eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Wed, 31 Aug 2022 10:11:45 +0300 Subject: [PATCH] Fixed #2908 - Improve Panel implementation for Accessibility --- api-generator/components/panel.js | 6 +++++ src/components/panel/Panel.d.ts | 4 +++ src/components/panel/Panel.vue | 13 ++++++--- src/views/panel/PanelDoc.vue | 44 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/api-generator/components/panel.js b/api-generator/components/panel.js index be66be2e7..5f5794bb9 100644 --- a/api-generator/components/panel.js +++ b/api-generator/components/panel.js @@ -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." } ]; diff --git a/src/components/panel/Panel.d.ts b/src/components/panel/Panel.d.ts index 34120c6dd..c6672e6b5 100755 --- a/src/components/panel/Panel.d.ts +++ b/src/components/panel/Panel.d.ts @@ -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 { diff --git a/src/components/panel/Panel.vue b/src/components/panel/Panel.vue index 99c82ef21..e3dd1709b 100755 --- a/src/components/panel/Panel.vue +++ b/src/components/panel/Panel.vue @@ -6,8 +6,8 @@
-
@@ -32,7 +32,8 @@ export default { props: { header: String, toggleable: Boolean, - collapsed: Boolean + collapsed: Boolean, + toggleButtonProps: String }, data() { return { @@ -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: { diff --git a/src/views/panel/PanelDoc.vue b/src/views/panel/PanelDoc.vue index 785589509..12735a8c4 100755 --- a/src/views/panel/PanelDoc.vue +++ b/src/views/panel/PanelDoc.vue @@ -113,6 +113,12 @@ import Panel from 'primevue/panel'; boolean null Defines the initial state of panel content. + + + toggleButtonProps + string + null + Uses to pass the custom value to read for the button inside the component. @@ -201,6 +207,44 @@ import Panel from 'primevue/panel'; +
Accessibility
+ +
Screen Reader
+

Toggleable panels use a content toggle button at the header that has aria-controls to define the id of the content section along with aria-expanded for the visibility state. The value to read the button + defaults to the value of the header property and can be customized by defining an aria-label or aria-labelledby via the toggleButtonProps property.

+

The content uses region, defines an id that matches the aria-controls of the content toggle button and aria-labelledby referring to the id of the header.

+ +
Content Toggle Button Keyboard Support
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
KeyFunction
tabMoves focus to the next the focusable element in the page tab sequence.
shift + tabMoves focus to the previous the focusable element in the page tab sequence.
enterToggles the visibility of the content.
spaceToggles the visibility of the content.
+
+
+
Dependencies

None.