Skip to content

Commit 0526ada

Browse files
committed
fix(material/chips): unable to add space when editing chip (#26564)
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. (cherry picked from commit 1186c80)
1 parent 57331b5 commit 0526ada

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/material/chips/chip-action.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class MatChipAction extends _MatChipActionMixinBase implements HasTabInde
8585
_handlePrimaryActionInteraction(): void;
8686
remove(): void;
8787
disabled: boolean;
88+
_isEditing?: boolean;
8889
},
8990
) {
9091
super();
@@ -110,7 +111,8 @@ export class MatChipAction extends _MatChipActionMixinBase implements HasTabInde
110111
(event.keyCode === ENTER || event.keyCode === SPACE) &&
111112
!this.disabled &&
112113
this.isInteractive &&
113-
this._isPrimary
114+
this._isPrimary &&
115+
!this._parentChip._isEditing
114116
) {
115117
event.preventDefault();
116118
this._parentChip._handlePrimaryActionInteraction();

src/material/chips/chip-row.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Directionality} from '@angular/cdk/bidi';
2-
import {BACKSPACE, DELETE, ENTER} from '@angular/cdk/keycodes';
2+
import {BACKSPACE, DELETE, ENTER, SPACE} from '@angular/cdk/keycodes';
33
import {
44
createKeyboardEvent,
55
dispatchEvent,
@@ -331,6 +331,14 @@ describe('MDC-based Row Chips', () => {
331331
flush();
332332
expect(document.activeElement).not.toBe(primaryAction);
333333
}));
334+
335+
it('should not prevent SPACE events when editing', fakeAsync(() => {
336+
const event = dispatchKeyboardEvent(getEditInput(), 'keydown', SPACE);
337+
fixture.detectChanges();
338+
flush();
339+
340+
expect(event.defaultPrevented).toBe(false);
341+
}));
334342
});
335343

336344
describe('a11y', () => {

0 commit comments

Comments
 (0)