Skip to content

Commit

Permalink
fix(checkbox): prevent second click event from input (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg authored Jul 24, 2019
1 parent 34cb370 commit 115ce08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/framework/theme/components/checkbox/checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ import { convertToBoolProperty } from '../helpers';
<label class="label">
<input type="checkbox" class="native-input visually-hidden"
[disabled]="disabled"
[checked]="value"
[checked]="checked"
(change)="updateValueAndIndeterminate($event)"
(blur)="setTouched()"
(click)="$event.stopPropagation()"
[indeterminate]="indeterminate">
<span [class.indeterminate]="indeterminate" [class.checked]="value" class="custom-checkbox">
<span [class.indeterminate]="indeterminate" [class.checked]="checked" class="custom-checkbox">
<nb-icon *ngIf="indeterminate" icon="minus-bold-outline" pack="nebular-essentials"></nb-icon>
<nb-icon *ngIf="value && !indeterminate" icon="checkmark-bold-outline" pack="nebular-essentials"></nb-icon>
<nb-icon *ngIf="checked && !indeterminate" icon="checkmark-bold-outline" pack="nebular-essentials"></nb-icon>
</span>
<span class="text">
<ng-content></ng-content>
Expand Down
9 changes: 9 additions & 0 deletions src/framework/theme/components/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ describe('Component: NbCheckbox', () => {
fixture.detectChanges();
expect(checkbox.indeterminate).toEqual(false);
});

it('should emit click event once', () => {
const clickSpy = jasmine.createSpy('checkbox click spy');
(fixture.nativeElement as HTMLElement).addEventListener('click', clickSpy);

label.nativeElement.click();

expect(clickSpy).toHaveBeenCalledTimes(1);
});
});

/** Test component with reactive forms */
Expand Down

0 comments on commit 115ce08

Please sign in to comment.