Skip to content

cypress-axe accessibility test fails: "ARIA role group is not allowed for given element" #825

Closed

Description

@j10sanders

Checks

Version

4.0.6

Description

Axe tests run in cypress-axe give this error:

"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!

Reproduction Link

No response

Steps to Reproduce

Test accessibility with axe-core in Cypress

Expected Behaviour

No errors for a basic splide component.

Activity

  1. NaotoshiFujita commented on Jun 11, 2022

    @NaotoshiFujita
    Collaborator

    After some research, this is because <li> does not accept role="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.

  2. attila-albert commented on Sep 21, 2024

    @attila-albert

    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();
    
  3. phl23 commented on Sep 26, 2024

    @phl23

    Good job @attila-albert

    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]);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions