Skip to content

Commit

Permalink
fix(module:table): should prevent tr click trigger when clicking expa…
Browse files Browse the repository at this point in the history
…nd (#2618)

close #2419
  • Loading branch information
cipchk authored and hsuanxyz committed Dec 11, 2018
1 parent c664c6f commit 88be1c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/table/nz-td.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<span
*ngIf="nzShowExpand"
class="ant-table-row-expand-icon"
(click)="expandChange()"
(click)="expandChange($event)"
[class.ant-table-row-expanded]="nzExpand"
[class.ant-table-row-collapsed]="!nzExpand"></span>
<ng-content></ng-content>
3 changes: 2 additions & 1 deletion components/table/nz-td.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export class NzTdComponent {
}
}

expandChange(): void {
expandChange(e: Event): void {
e.stopPropagation();
this.nzExpand = !this.nzExpand;
this.nzExpandChange.emit(this.nzExpand);
}
Expand Down
11 changes: 11 additions & 0 deletions components/table/nz-td.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 88be1c3

Please sign in to comment.