Skip to content

Commit

Permalink
fix(material/list): enable MacOS select all with command+a (angular#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewseguin authored Dec 16, 2024
1 parent b924e86 commit 4697d8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/material/list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material/list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4697d8e

Please sign in to comment.