Skip to content

Commit 9463dfe

Browse files
committed
feat(material/core): Add ARIA attribute 'aria-selected' to option when its value is set to false
Add ARIA attribute 'aria-selected' to option when its value is set to false fixes: #26642 BREAKING CHANGE: no
1 parent 3c53deb commit 9463dfe

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/material/core/option/option.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,23 @@ describe('MatOption component', () => {
204204
expect(optionNativeElement.classList.contains('mat-mdc-focus-indicator')).toBe(true);
205205
});
206206

207+
it('should have the correct aria-selected', () => {
208+
const fixture = TestBed.createComponent(BasicOption);
209+
fixture.detectChanges();
210+
211+
const optionNativeElement: HTMLElement = fixture.debugElement.query(
212+
By.directive(MatOption),
213+
)!.nativeElement;
214+
const optionInstance: MatOption = fixture.debugElement.query(
215+
By.directive(MatOption),
216+
)!.componentInstance;
217+
218+
optionInstance.deselect();
219+
fixture.detectChanges();
220+
221+
expect(optionNativeElement.getAttribute('aria-selected')).toBe('false');
222+
});
223+
207224
describe('inside inert group', () => {
208225
let fixture: ComponentFixture<InsideGroup>;
209226

src/material/core/option/option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class _MatOptionBase<T = any> implements FocusableOption, AfterViewChecke
211211
* information.
212212
*/
213213
_getAriaSelected(): boolean | null {
214-
return this.selected || (this.multiple ? false : null);
214+
return this.selected;
215215
}
216216

217217
/** Returns the correct tabindex for the option depending on disabled state. */

0 commit comments

Comments
 (0)