components icon indicating copy to clipboard operation
components copied to clipboard

bug(Material Stepper): Certain ARIA roles must contain particular children Error

Open crumbyshirt opened this issue 2 years ago • 13 comments

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

The documentation for the stepper appears to indicate that this should not be occurring based on the role for the stepper being a tablist and the roles for steps being tab. I think the problem comes from some interim nodes between the tabs and the tablist.

Reproduction

Steps to reproduce:

  1. navigate to the material stepper examples page: https://rc.material.angular.io/components/stepper/examples
  2. run a scan of it using the axe def tool chrome extension: https://chrome.google.com/webstore/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US
  3. You will see that it will result in 14 instances of the error "Certain ARIA roles must contain particular children". That is one for each stepper on the example page.

Expected Behavior

Running the WCAG2.1 AA compliance scan should not find the "Certain ARIA roles must contain particular children" issue which is considered a critical aria issue.

Actual Behavior

Running the WCAG2.1 AA compliance scan finds the "Certain ARIA roles must contain particular children" issue which is considered a critical aria issue.

There is no clear way to resolve this issue with the stepper component.

Environment

  • Angular: 15
  • CDK/Material: 15.1.0
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

crumbyshirt avatar Jan 17 '23 14:01 crumbyshirt

I looked into this one. Fixing it for a horizontal stepper is straightforward since we just need to move the role to a different element, but it'll be difficult to fix for a vertical one, because the tabs and tab labels have to be siblings. That being said, I don't think that this affects users.

crisbeto avatar Jan 21 '23 09:01 crisbeto

@crisbeto What do you mean when you say 'move the role to a different element'. You mean on your side when the update is done or ill put it manually.

Heres my html:

<mat-horizontal-stepper linear #stepper labelPosition="bottom" (selectionChange)="onStepChange($event)">
 <ng-template matStepperIcon="edit" let-index="index">
        {{index + 1}}
      </ng-template>
      <ng-template matStepperIcon="done" let-index="index">
        {{index + 1}}
      </ng-template>
      <ng-template matStepperIcon="number" let-index="index">
        {{index + 1}}
      </ng-template>

 <mat-step  [stepControl]="sample.control" [editable]="!isSaving">
</mat-step>
<mat-step role="tab" [stepControl]="sample.control" [editable]="!isSaving">
</mat-step>
 <mat-step role="tab" [stepControl]="sample.control" [editable]="!isSaving">
</mat-step>
 <mat-step role="tab" [editable]="!isSaving">
</mat-step>
    </mat-horizontal-stepper>

jimmuel-agwit-115094 avatar Jan 17 '24 06:01 jimmuel-agwit-115094

I second what @JimAgwit said. @crisbeto Which element has its role moved, and to which element is the role moved to? Thanks in advance.

vandents avatar Jun 21 '24 17:06 vandents

This issue is still present in mat-stepper. Any solution to fix this accessibility issue?

Jayaranjani avatar Dec 17 '24 11:12 Jayaranjani

This issue is still present in mat-stepper. Any solution to fix this accessibility issue?

I think this issue is already resolve in the past patch. I confirmed this by manually checking the accessibility on our end. But im not sure, it seems that I passed the test.

jimmuel-agwit-115094 avatar Dec 17 '24 23:12 jimmuel-agwit-115094

I think this issue is already resolve in the past patch. I confirmed this by manually checking the accessibility on our end. But im not sure, it seems that I passed the test.

@JimAgwit What angular version are you using? I'm currently at version 17 and still encountering it on my end.

vistajess avatar Jan 13 '25 13:01 vistajess

This issue is still present in mat-stepper. Any solution to fix this accessibility issue?

I think this issue is already resolve in the past patch. I confirmed this by manually checking the accessibility on our end. But im not sure, it seems that I passed the test.

I am using Angular-15.2.7 & I could still see the issue occurring!

Jayaranjani avatar Jan 23 '25 08:01 Jayaranjani

I'm in Angular Material 18.2.4. Still happening. This is happening because the role="tablist" is incorrectly assigned to the "mat-stepper-horizontal" element causing the issue

"Element has children which are not allowed: [role=tabpanel]"

. A workaround before they fix it in Angular Material is moving role="tablist" to the "mat-horizontal-stepper-header-container" element. Do this after view init on the stepper's page(assuming only on stepper on the page):

horizontalStepperRoleFix() {
   document.getElementsByClassName('mat-horizontal-stepper-header-container')[0].setAttribute('role', 'tablist');
   document.getElementsByClassName('mat-stepper-horizontal')[0].removeAttribute('role');
 }

Didn't use the vertical one though.

pzhu-quantumit avatar Mar 14 '25 06:03 pzhu-quantumit

This is still happening in Angular Material 19.2.6.

We have an application with a horizontal stepper, that changes to a vertical stepper responsively for smaller screen sizes. The above workaround posted by @pzhu-quantumit works for the horizontal, but not the vertical.

The issue is that there is a role="tab-panel" created under each role="tab" in a role="tab-list" element, which is not allowed.

Attempts to use the workaround for the vertical stepper create a cascade of other issues, so we did not implement it for this case.

Roffeyaa avatar Jun 03 '25 15:06 Roffeyaa

This issue is still causing issues for me in Angular 18. Will this be addressed?

conorjohn avatar Sep 25 '25 16:09 conorjohn

This needs addressing. It's causing issues for users with accessibility requirements.

joshuajaharwood avatar Oct 02 '25 15:10 joshuajaharwood

Just done some digging through the sources. This was fixed in ff10f044826323811eee0f918e9c1515a5514c5e, so it should be released with Angular 21.

joshuajaharwood avatar Oct 02 '25 16:10 joshuajaharwood

I'm in Angular Material 18.2.4. Still happening. This is happening because the role="tablist" is incorrectly assigned to the "mat-stepper-horizontal" element causing the issue

"Element has children which are not allowed: [role=tabpanel]"

. A workaround before they fix it in Angular Material is moving role="tablist" to the "mat-horizontal-stepper-header-container" element. Do this after view init on the stepper's page(assuming only on stepper on the page):

horizontalStepperRoleFix() {
   document.getElementsByClassName('mat-horizontal-stepper-header-container')[0].setAttribute('role', 'tablist');
   document.getElementsByClassName('mat-stepper-horizontal')[0].removeAttribute('role');
 }

Didn't use the vertical one though.

For the workaround we implemented, you're also going to want to move the aria-orientation attribute from mat-stepper-horizontal to mat-horizontal-stepper-header-container. I used https://github.com/angular/components/commit/ff10f044826323811eee0f918e9c1515a5514c5e as a reference.

joshuajaharwood avatar Nov 11 '25 11:11 joshuajaharwood