Skip to content

Commit b6c5fb4

Browse files
andrewseguinjosephperrott
authored andcommitted
Revert "fix(chips): event propagation not stopped by remove button (angular#8772)" (angular#9064)
1 parent 2b2eb18 commit b6c5fb4

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

src/lib/chips/chip-remove.spec.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import {Component, DebugElement} from '@angular/core';
22
import {By} from '@angular/platform-browser';
3-
import {fakeAsync, ComponentFixture, TestBed} from '@angular/core/testing';
3+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
44
import {MatChip, MatChipsModule} from './index';
5-
import {dispatchFakeEvent} from '@angular/cdk/testing';
65

76
describe('Chip Remove', () => {
87
let fixture: ComponentFixture<any>;
98
let testChip: TestChip;
109
let chipDebugElement: DebugElement;
1110
let chipNativeElement: HTMLElement;
1211

13-
beforeEach(fakeAsync(() => {
12+
beforeEach(async(() => {
1413
TestBed.configureTestingModule({
1514
imports: [MatChipsModule],
1615
declarations: [
@@ -19,6 +18,9 @@ describe('Chip Remove', () => {
1918
});
2019

2120
TestBed.compileComponents();
21+
}));
22+
23+
beforeEach(async(() => {
2224
fixture = TestBed.createComponent(TestChip);
2325
testChip = fixture.debugElement.componentInstance;
2426
fixture.detectChanges();
@@ -28,14 +30,14 @@ describe('Chip Remove', () => {
2830
}));
2931

3032
describe('basic behavior', () => {
31-
it('should apply the `mat-chip-remove` CSS class', () => {
32-
const hrefElement = chipNativeElement.querySelector('a')!;
33+
it('should applies the `mat-chip-remove` CSS class', () => {
34+
let hrefElement = chipNativeElement.querySelector('a')!;
3335

3436
expect(hrefElement.classList).toContain('mat-chip-remove');
3537
});
3638

37-
it('should emit (remove) on click', () => {
38-
const hrefElement = chipNativeElement.querySelector('a')!;
39+
it('should emits (remove) on click', () => {
40+
let hrefElement = chipNativeElement.querySelector('a')!;
3941

4042
testChip.removable = true;
4143
fixture.detectChanges();
@@ -46,19 +48,6 @@ describe('Chip Remove', () => {
4648

4749
expect(testChip.didRemove).toHaveBeenCalled();
4850
});
49-
50-
it('should prevent the default click action', () => {
51-
const hrefElement = chipNativeElement.querySelector('a')!;
52-
53-
testChip.removable = true;
54-
fixture.detectChanges();
55-
56-
const event = dispatchFakeEvent(hrefElement, 'click');
57-
fixture.detectChanges();
58-
59-
expect(event.defaultPrevented).toBe(true);
60-
});
61-
6251
});
6352
});
6453

src/lib/chips/chip.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,22 +308,17 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
308308
selector: '[matChipRemove]',
309309
host: {
310310
'class': 'mat-chip-remove',
311-
'(click)': '_handleClick($event)',
311+
'(click)': '_handleClick()',
312312
}
313313
})
314314
export class MatChipRemove {
315315
constructor(protected _parentChip: MatChip) {
316316
}
317317

318318
/** Calls the parent chip's public `remove()` method if applicable. */
319-
_handleClick(event: MouseEvent): void {
319+
_handleClick(): void {
320320
if (this._parentChip.removable) {
321321
this._parentChip.remove();
322-
323-
// Note: the parent chip does something similar, however since we're removing it,
324-
// its event handler will be unbound before it has had the chance to fire.
325-
event.preventDefault();
326-
event.stopPropagation();
327322
}
328323
}
329324
}

0 commit comments

Comments
 (0)