Select > Dropdown accessiblity Issue

Viewed 4487

I have the following HTML code:

<mat-form-field >
 <mat-label>Favorite food</mat-label>
 <mat-select>
 <mat-option role="option" *ngFor="let food of foods" [value]="food.value">
 {{food.viewValue}}
 </mat-option>
 </mat-select>
 </mat-form-field>

and the below HTML is rendered in the browser after I run the application:

<mat-select _ngcontent-c12="" class="form-control mat-select ng-tns-c21-23 mat-
select-empty ng-star-inserted" role="listbox" id="mat-select-10" tabindex="0" aria-labelledby="mat-form-field-label-21" aria-required="false" aria-disabled="false" aria-invalid="false" aria-multiselectable="false">
<div class="mat-select-trigger" aria-hidden="true" cdk-overlay-origin=""><div class="mat-select-value" ng-reflect-ng-switch="true"><!--bindings={
  "ng-reflect-ng-switch-case": "true"
}--><span class="mat-select-placeholder ng-tns-c21-23 ng-star-inserted">&nbsp;</span><!--bindings={
  "ng-reflect-ng-switch-case": "false"
}--></div><div class="mat-select-arrow-wrapper"><div class="mat-select-arrow"></div></div></div><!--bindings={
  "ng-reflect-origin": "[object Object]",
  "ng-reflect-positions": "[object Object],[object Object",
  "ng-reflect-offset-y": "-12",
  "ng-reflect-min-width": "325",
  "ng-reflect-backdrop-class": "cdk-overlay-transparent-backdr",
  "ng-reflect-scroll-strategy": "[object Object]",
  "ng-reflect-open": "false",
  "ng-reflect-has-backdrop": "",
  "ng-reflect-lock-position": ""
}--></mat-select>

When I open the dropdown, I get this ng options:

<mat-option _ngcontent-c12="" class="mat-option ng-star-inserted mat-active" role="option" ng-reflect-value="value1" tabindex="0" id="mat-option-4" aria-disabled="false"><!--bindings={
  "ng-reflect-ng-if": "false"
}--><span class="mat-option-text"> viewValue1 </span><div class="mat-option-ripple mat-ripple" mat-ripple="" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLElement]"></div></mat-option>

I am getting an error: Required ARIA child role not present: option. I am new to this, and I have tried adding aria-label, and I gave an id to mat-options. It's not working. Can any one help me solve this one?

2 Answers

No need to pass the role attribute. The error means that "option" is an invalid value or the attribute "role". It should work fine without it.

Related