From 88be1c3dc255333223a9007fae5bed0c23fe3d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Tue, 11 Dec 2018 18:56:32 +0800 Subject: [PATCH] fix(module:table): should prevent tr click trigger when clicking expand (#2618) close #2419 --- components/table/nz-td.component.html | 2 +- components/table/nz-td.component.ts | 3 ++- components/table/nz-td.spec.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/table/nz-td.component.html b/components/table/nz-td.component.html index d781db0a790..2a4eb3f8408 100644 --- a/components/table/nz-td.component.html +++ b/components/table/nz-td.component.html @@ -13,7 +13,7 @@ \ No newline at end of file diff --git a/components/table/nz-td.component.ts b/components/table/nz-td.component.ts index 0ab3bc58a5c..b400c3f0465 100644 --- a/components/table/nz-td.component.ts +++ b/components/table/nz-td.component.ts @@ -102,7 +102,8 @@ export class NzTdComponent { } } - expandChange(): void { + expandChange(e: Event): void { + e.stopPropagation(); this.nzExpand = !this.nzExpand; this.nzExpandChange.emit(this.nzExpand); } diff --git a/components/table/nz-td.spec.ts b/components/table/nz-td.spec.ts index 4d99d997b15..2b1bdb949dc 100644 --- a/components/table/nz-td.spec.ts +++ b/components/table/nz-td.spec.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import { fakeAsync, flush, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; +import { createFakeEvent } from '../core/testing'; import { NzTableModule } from './nz-table.module'; import { NzTdComponent } from './nz-td.component'; @@ -100,6 +101,16 @@ describe('nz-td', () => { expect(td.nativeElement.querySelector('.ant-table-row-expand-icon').classList).toContain('ant-table-row-expanded'); expect(testComponent.expandChange).toHaveBeenCalledTimes(1); }); + it('should click expand event stopPropagation', () => { + testComponent.showExpand = true; + fixture.detectChanges(); + const input: HTMLElement = td.nativeElement.querySelector('.ant-table-row-expand-icon'); + const fakeInputChangeEvent = createFakeEvent('click', true, true); + spyOn(fakeInputChangeEvent, 'stopPropagation'); + input.dispatchEvent(fakeInputChangeEvent); + fixture.detectChanges(); + expect(fakeInputChangeEvent.stopPropagation).toHaveBeenCalled(); + }); it('should be row index when index-size is 0', () => { testComponent.indentSize = 0; fixture.detectChanges();