Skip to content

feat(material/core): Add ARIA attribute 'aria-selected' to option when its value is set to false #26661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/material/core/option/option.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InsideGroup>;

Expand Down
2 changes: 1 addition & 1 deletion src/material/core/option/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class _MatOptionBase<T = any> 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. */
Expand Down