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(select): prevent opening of disabled select when clicking on toggle #1865

Merged
merged 3 commits into from
Jul 29, 2019
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
3 changes: 2 additions & 1 deletion src/framework/theme/components/select/select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<ng-template #placeholderTemplate>{{ placeholder }}</ng-template>

<nb-icon aria-hidden="true" icon="chevron-down-outline" pack="nebular-essentials"></nb-icon>
<nb-icon icon="chevron-down-outline" pack="nebular-essentials" (click)="disabled && $event.stopPropagation()" aria-hidden="true">
</nb-icon>
</button>

<div *nbPortal [ngClass]="optionsListClasses" [style.width.px]="hostWidth" class="options-list-container">
Expand Down
26 changes: 26 additions & 0 deletions src/framework/theme/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,32 @@ describe('Component: NbSelectComponent', () => {
expect(selectComponent.hostWidth).not.toEqual(selectElement.offsetWidth);
expect(selectComponent.hostWidth).toEqual(buttonElement.offsetWidth);
});

it('should not open when disabled and button clicked', fakeAsync(() => {
const selectFixture = TestBed.createComponent(NbSelectComponent);
selectFixture.componentInstance.disabled = true;
selectFixture.detectChanges();
const selectButton: HTMLElement = selectFixture.debugElement.query(By.css('button')).nativeElement;

selectButton.click();
flush();
fixture.detectChanges();

expect(selectFixture.componentInstance.isOpen).toBeFalsy();
}));

it('should not open when disabled and toggle icon clicked', fakeAsync(() => {
const selectFixture = TestBed.createComponent(NbSelectComponent);
selectFixture.componentInstance.disabled = true;
selectFixture.detectChanges();
const selectToggleIcon: HTMLElement = selectFixture.debugElement.query(By.css('nb-icon')).nativeElement;

selectToggleIcon.click();
flush();
fixture.detectChanges();

expect(selectFixture.componentInstance.isOpen).toBeFalsy();
}));
});

describe('NbSelectComponent - falsy values', () => {
Expand Down