Skip to content

Commit 050b59b

Browse files
committed
fix(material/list): enable MacOS select all with command+a (#30183)
(cherry picked from commit 4697d8e)
1 parent 125d867 commit 050b59b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/material/list/selection-list.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ describe('MatSelectionList without forms', () => {
363363
expect(event.defaultPrevented).toBe(true);
364364
});
365365

366-
it('should select all items using ctrl + a', () => {
366+
it('should select and deselect all items using ctrl + a', () => {
367367
listOptions.forEach(option => (option.componentInstance.disabled = false));
368368
fixture.changeDetectorRef.markForCheck();
369369
fixture.detectChanges();
@@ -375,6 +375,29 @@ describe('MatSelectionList without forms', () => {
375375
fixture.detectChanges();
376376

377377
expect(listOptions.every(option => option.componentInstance.selected)).toBe(true);
378+
379+
dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {control: true});
380+
fixture.detectChanges();
381+
382+
expect(listOptions.every(option => option.componentInstance.selected)).toBe(false);
383+
});
384+
385+
it('should select and deselect all items using meta + a', () => {
386+
listOptions.forEach(option => (option.componentInstance.disabled = false));
387+
fixture.changeDetectorRef.markForCheck();
388+
fixture.detectChanges();
389+
390+
expect(listOptions.some(option => option.componentInstance.selected)).toBe(false);
391+
392+
listOptions[2].nativeElement.focus();
393+
dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {meta: true});
394+
fixture.detectChanges();
395+
396+
expect(listOptions.every(option => option.componentInstance.selected)).toBe(true);
397+
dispatchKeyboardEvent(listOptions[2].nativeElement, 'keydown', A, 'A', {meta: true});
398+
fixture.detectChanges();
399+
400+
expect(listOptions.every(option => option.componentInstance.selected)).toBe(false);
378401
});
379402

380403
it('should not select disabled items when pressing ctrl + a', () => {

src/material/list/selection-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class MatSelectionList
379379
event.keyCode === A &&
380380
this.multiple &&
381381
!this._keyManager.isTyping() &&
382-
hasModifierKey(event, 'ctrlKey')
382+
hasModifierKey(event, 'ctrlKey', 'metaKey')
383383
) {
384384
const shouldSelect = this.options.some(option => !option.disabled && !option.selected);
385385
event.preventDefault();

0 commit comments

Comments
 (0)