Skip to content
Merged
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
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 @@ -375,7 +375,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
Loading