Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:table): should prevent tr click trigger when clicking expand #2618

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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