You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cypress-axe accessibility test fails: "ARIA role group is not allowed for given element" #825
"id": "aria-allowed-role",
"impact": "minor",
"tags": [
"cat.aria",
"best-practice"
],
"description": "Ensures role attribute has an appropriate value for the element",
"help": "ARIA role should be appropriate for the element",
"helpUrl": "https://dequeuniversity.com/rules/axe/4.2/aria-allowed-role?application=axeAPI",
"nodes": [
{
"any": [
{
"id": "aria-allowed-role",
"data": [
"group"
],
"relatedNodes": [],
"impact": "minor",
"message": "ARIA role group is not allowed for given element"
}
],
"all": [],
"none": [],
"impact": "minor",
"html": "<li class="splide__slide gamut-9iq18i-SplideSlide efok5bj0 is-active is-visible" id="splide01-slide01" role="group" aria-roledescription="slide" aria-label="1 of 1" style="width: calc(100%);">",
"target": [
"#splide01-slide01"
],
"failureSummary": "Fix any of the following:\n ARIA role group is not allowed for given element"
}
]
}
I've tried changing the role to various options but can't find anything that will pass these tests. I can skip this check if you think this is an issue on cypress-axe's end!
I came up with this solution, that does the job :)
// Use the 'mounted' event to modify slide attributes after Splide mounts
splide.on('mounted', function () {
let slides = elms[i].querySelectorAll('.splide__slide');
let slideList = elms[i].querySelector('.splide__list'); // Use querySelector for a single element
// Modify the slides
slides.forEach(function (slide) {
slide.removeAttribute('role'); // Remove invalid role
slide.setAttribute('role', 'listitem'); // Add valid role
});
// Modify the slide list
if (slideList) {
slideList.removeAttribute('role'); // Remove the invalid role
slideList.setAttribute('role', 'list'); // Add a valid role
}
});
// Mount the Splide instance
splide.mount();
Here is a Typescript version for react with createRef
"use client";
import Splide from "@splidejs/splide";
// Create a ref to the Splide component
const splideRef = createRef<HTMLDivElement>();
// Mount the Splide slider
useEffect(() => {
if (!splideRef.current) return;
// Create a Splide instance
const splide: Splide = new Splide(splideRef.current, {});
// Use the 'mounted' event to modify slide attributes after Splide mounts
splide.on("mounted", function () {
const slides =
splideRef?.current?.querySelectorAll(".splide__slide");
const slideList =
splideRef?.current?.querySelector(".splide__list"); // Use querySelector for a single element
// Modify the slides
slides?.forEach(function (slide) {
slide.removeAttribute("role"); // Remove invalid role
slide.setAttribute("role", "listitem"); // Add valid role
});
// Modify the slide list
slideList?.removeAttribute("role"); // Remove the invalid role
slideList?.setAttribute("role", "list"); // Add a valid role
});
// Mount the Splide instance
splide.mount();
return () => {
splide.destroy();
};
}, [splideRef]);
Activity
NaotoshiFujita commentedon Jun 11, 2022
After some research, this is because
<li>does not acceptrole="group".By the historical reason, this cannot be fixed soon.
Using
<div>instead of<ul>and<li>will get rid of the issue, I guess.attila-albert commentedon Sep 21, 2024
I came up with this solution, that does the job :)
phl23 commentedon Sep 26, 2024
Good job @attila-albert
Here is a Typescript version for react with createRef