bug(Material Stepper): Certain ARIA roles must contain particular children Error
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:
- navigate to the material stepper examples page: https://rc.material.angular.io/components/stepper/examples
- 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
- 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
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 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>
I second what @JimAgwit said. @crisbeto Which element has its role moved, and to which element is the role moved to? Thanks in advance.
This issue is still present in mat-stepper. Any solution to fix this accessibility issue?
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 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.
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!
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.
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.
This issue is still causing issues for me in Angular 18. Will this be addressed?
This needs addressing. It's causing issues for users with accessibility requirements.
Just done some digging through the sources. This was fixed in ff10f044826323811eee0f918e9c1515a5514c5e, so it should be released with Angular 21.
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.