-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: destroy dropdown panel on close (#286)
- Loading branch information
Showing
26 changed files
with
756 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.ng-dropdown-panel { | ||
box-sizing: border-box; | ||
position: absolute; | ||
width: 100%; | ||
z-index: 3; | ||
-webkit-overflow-scrolling: touch; | ||
.ng-dropdown-panel-items { | ||
display: block; | ||
height: auto; | ||
-webkit-box-sizing: border-box; | ||
-moz-box-sizing: border-box; | ||
box-sizing: border-box; | ||
max-height: 240px; | ||
overflow-y: auto; | ||
.ng-option { | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
display: block; | ||
.highlighted { | ||
font-weight: bold; | ||
text-decoration: underline; | ||
} | ||
&.disabled { | ||
cursor: default; | ||
} | ||
} | ||
} | ||
|
||
.scroll-host { | ||
overflow: hidden; | ||
overflow-y: auto; | ||
position: relative; | ||
display: block; | ||
-webkit-overflow-scrolling: touch; | ||
} | ||
.scrollable-content { | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
} | ||
.total-padding { | ||
width: 1px; | ||
opacity: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Component, Injectable, ViewChild, ErrorHandler, NgZone } from '@angular/core'; | ||
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; | ||
import { NgDropdownPanelComponent } from './ng-dropdown-panel.component'; | ||
import { NgSelectComponent } from './ng-select.component'; | ||
import { WindowService } from './window.service'; | ||
import { VirtualScrollService } from './virtual-scroll.service'; | ||
import { ItemsList } from './items-list'; | ||
import { MockNgZone, MockNgWindow } from '../testing/mocks'; | ||
import { TestsErrorHandler } from '../testing/helpers'; | ||
|
||
@Component({ | ||
template: ` | ||
<ng-dropdown-panel *ngIf="isOpen" | ||
class="ng-dropdown-panel" | ||
[items]="itemsList.filteredItems" | ||
(update)="viewPortItems = $event"> | ||
<div class="ng-option" *ngFor="let item of viewPortItems">{{item.label}}</div> | ||
</ng-dropdown-panel> | ||
` | ||
}) | ||
@Injectable() | ||
class MockNgSelect { | ||
@ViewChild(NgDropdownPanelComponent) dropdownPanel: NgDropdownPanelComponent; | ||
itemsList = new ItemsList(<any>this); | ||
viewPortItems = []; | ||
isOpen = true; | ||
} | ||
|
||
describe('NgDropdowPanel', function () { | ||
let fixture: ComponentFixture<MockNgSelect>; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.configureTestingModule({ | ||
providers: [ | ||
VirtualScrollService, | ||
{ provide: ErrorHandler, useClass: TestsErrorHandler }, | ||
{ provide: NgZone, useFactory: () => new MockNgZone() }, | ||
{ provide: WindowService, useFactory: () => new MockNgWindow() }, | ||
{ provide: NgSelectComponent, useClass: MockNgSelect }, | ||
], | ||
declarations: [ | ||
NgDropdownPanelComponent, | ||
MockNgSelect | ||
] | ||
}).createComponent(MockNgSelect); | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should render items', async(() => { | ||
fixture.componentInstance.itemsList.setItems(['A', 'B', 'C'], true); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
expect(fixture.componentInstance.dropdownPanel.items.length).toBe(3); | ||
const options = fixture.debugElement.nativeElement.querySelectorAll('.ng-option'); | ||
expect(options.length).toBe(3); | ||
expect(options[0].innerText).toBe('A'); | ||
expect(options[1].innerText).toBe('B'); | ||
expect(options[2].innerText).toBe('C'); | ||
}); | ||
})); | ||
|
||
it('should not render items when items length is zero', async(() => { | ||
fixture.componentInstance.itemsList.setItems([]); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
expect(fixture.componentInstance.dropdownPanel.items.length).toBe(0); | ||
const options = fixture.debugElement.nativeElement.querySelectorAll('.ng-option'); | ||
expect(options.length).toBe(0); | ||
}); | ||
})); | ||
|
||
}); | ||
|
Oops, something went wrong.