From 1542c01823fd233aa6159c13aec717360cb3c01c Mon Sep 17 00:00:00 2001 From: Michael Bourne Date: Thu, 29 Aug 2024 03:44:16 -0600 Subject: [PATCH] feat(a11y): add `containerRole` parameter (#7708) * Add containerRole parameter to a11y module To fix accessibility error related to aria-roledescription * add types --------- Co-authored-by: Vladimir Kharlampidi --- src/modules/a11y/a11y.mjs | 4 ++++ src/types/modules/a11y.d.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/modules/a11y/a11y.mjs b/src/modules/a11y/a11y.mjs index 97ead239d..f76177d83 100644 --- a/src/modules/a11y/a11y.mjs +++ b/src/modules/a11y/a11y.mjs @@ -15,6 +15,7 @@ export default function A11y({ swiper, extendParams, on }) { slideLabelMessage: '{{index}} / {{slidesLength}}', containerMessage: null, containerRoleDescriptionMessage: null, + containerRole: null, itemRoleDescriptionMessage: null, slideRole: 'group', id: null, @@ -302,6 +303,9 @@ export default function A11y({ swiper, extendParams, on }) { if (params.containerMessage) { addElLabel(containerEl, params.containerMessage); } + if (params.containerRole) { + addElRole(containerEl, params.containerRole); + } // Wrapper const wrapperEl = swiper.wrapperEl; diff --git a/src/types/modules/a11y.d.ts b/src/types/modules/a11y.d.ts index 67cb64a57..21b352a20 100644 --- a/src/types/modules/a11y.d.ts +++ b/src/types/modules/a11y.d.ts @@ -66,6 +66,13 @@ export interface A11yOptions { */ containerRoleDescriptionMessage?: string | null; + /** + * Value of the "role" attribute to be set on the swiper container + * + * @default null + */ + containerRole?: string | null; + /** * Message for screen readers describing the role of slide element *