diff --git a/src/material/list/selection-list.spec.ts b/src/material/list/selection-list.spec.ts index 3bff0576717d..09b6c7233961 100644 --- a/src/material/list/selection-list.spec.ts +++ b/src/material/list/selection-list.spec.ts @@ -363,7 +363,7 @@ describe('MatSelectionList without forms', () => { expect(event.defaultPrevented).toBe(true); }); - it('should select all items using ctrl + a', () => { + it('should select and deselect all items using ctrl + a', () => { listOptions.forEach(option => (option.componentInstance.disabled = false)); fixture.changeDetectorRef.markForCheck(); fixture.detectChanges(); @@ -375,6 +375,29 @@ describe('MatSelectionList without forms', () => { fixture.detectChanges(); expect(listOptions.every(option => option.componentInstance.selected)).toBe(true); + + dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {control: true}); + fixture.detectChanges(); + + expect(listOptions.every(option => option.componentInstance.selected)).toBe(false); + }); + + it('should select and deselect all items using meta + a', () => { + listOptions.forEach(option => (option.componentInstance.disabled = false)); + fixture.changeDetectorRef.markForCheck(); + fixture.detectChanges(); + + expect(listOptions.some(option => option.componentInstance.selected)).toBe(false); + + listOptions[2].nativeElement.focus(); + dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {meta: true}); + fixture.detectChanges(); + + expect(listOptions.every(option => option.componentInstance.selected)).toBe(true); + dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {meta: true}); + fixture.detectChanges(); + + expect(listOptions.every(option => option.componentInstance.selected)).toBe(false); }); it('should not select disabled items when pressing ctrl + a', () => { diff --git a/src/material/list/selection-list.ts b/src/material/list/selection-list.ts index 1b21344e6ad2..0ab2b754d26a 100644 --- a/src/material/list/selection-list.ts +++ b/src/material/list/selection-list.ts @@ -379,7 +379,7 @@ export class MatSelectionList event.keyCode === A && this.multiple && !this._keyManager.isTyping() && - hasModifierKey(event, 'ctrlKey') + hasModifierKey(event, 'ctrlKey', 'metaKey') ) { const shouldSelect = this.options.some(option => !option.disabled && !option.selected); event.preventDefault();