From 9463dfe95f7a3d2d78d0a14f9b0ecf57a7661404 Mon Sep 17 00:00:00 2001 From: hamza jazyri Date: Mon, 20 Feb 2023 18:27:55 +0100 Subject: [PATCH] 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 --- src/material/core/option/option.spec.ts | 17 +++++++++++++++++ src/material/core/option/option.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/material/core/option/option.spec.ts b/src/material/core/option/option.spec.ts index d88974fc51f2..d29cc373729a 100644 --- a/src/material/core/option/option.spec.ts +++ b/src/material/core/option/option.spec.ts @@ -204,6 +204,23 @@ describe('MatOption component', () => { expect(optionNativeElement.classList.contains('mat-mdc-focus-indicator')).toBe(true); }); + it('should have the correct aria-selected', () => { + const fixture = TestBed.createComponent(BasicOption); + fixture.detectChanges(); + + const optionNativeElement: HTMLElement = fixture.debugElement.query( + By.directive(MatOption), + )!.nativeElement; + const optionInstance: MatOption = fixture.debugElement.query( + By.directive(MatOption), + )!.componentInstance; + + optionInstance.deselect(); + fixture.detectChanges(); + + expect(optionNativeElement.getAttribute('aria-selected')).toBe('false'); + }); + describe('inside inert group', () => { let fixture: ComponentFixture; diff --git a/src/material/core/option/option.ts b/src/material/core/option/option.ts index 2f427ff9b256..2cbde1ce989a 100644 --- a/src/material/core/option/option.ts +++ b/src/material/core/option/option.ts @@ -211,7 +211,7 @@ export class _MatOptionBase implements FocusableOption, AfterViewChecke * information. */ _getAriaSelected(): boolean | null { - return this.selected || (this.multiple ? false : null); + return this.selected; } /** Returns the correct tabindex for the option depending on disabled state. */