Skip to content

Commit

Permalink
fix(material/chips): unable to add space when editing chip (#26564)
Browse files Browse the repository at this point in the history
Fixes that the default action of the spacebar was being prevented while the chip is in its editing state, not allowing users to enter whitespace.
  • Loading branch information
crisbeto authored Feb 7, 2023
1 parent e6536b7 commit 1186c80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/material/chips/chip-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class MatChipAction extends _MatChipActionMixinBase implements HasTabInde
_handlePrimaryActionInteraction(): void;
remove(): void;
disabled: boolean;
_isEditing?: boolean;
},
) {
super();
Expand All @@ -110,7 +111,8 @@ export class MatChipAction extends _MatChipActionMixinBase implements HasTabInde
(event.keyCode === ENTER || event.keyCode === SPACE) &&
!this.disabled &&
this.isInteractive &&
this._isPrimary
this._isPrimary &&
!this._parentChip._isEditing
) {
event.preventDefault();
this._parentChip._handlePrimaryActionInteraction();
Expand Down
10 changes: 9 additions & 1 deletion src/material/chips/chip-row.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directionality} from '@angular/cdk/bidi';
import {BACKSPACE, DELETE, ENTER} from '@angular/cdk/keycodes';
import {BACKSPACE, DELETE, ENTER, SPACE} from '@angular/cdk/keycodes';
import {
createKeyboardEvent,
dispatchEvent,
Expand Down Expand Up @@ -331,6 +331,14 @@ describe('MDC-based Row Chips', () => {
flush();
expect(document.activeElement).not.toBe(primaryAction);
}));

it('should not prevent SPACE events when editing', fakeAsync(() => {
const event = dispatchKeyboardEvent(getEditInput(), 'keydown', SPACE);
fixture.detectChanges();
flush();

expect(event.defaultPrevented).toBe(false);
}));
});

describe('a11y', () => {
Expand Down

0 comments on commit 1186c80

Please sign in to comment.