Skip to content

Commit

Permalink
refactor(select): extract conditional code into separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg committed Apr 25, 2019
1 parent 17f2e1b commit c8822b2
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/framework/theme/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,19 +670,8 @@ export class NbSelectComponent<T> implements AfterViewInit, AfterContentInit, On

show() {
if (this.isHidden) {
if (!this.ref) {
this.createOverlay();
this.subscribeOnPositionChange();
this.createKeyManager();
this.subscribeOnOverlayKeys();
}

this.ref.attach(this.portal);
if (this.selectionModel.length) {
this.keyManager.setActiveItem(this.selectionModel[0]);
} else {
this.keyManager.setFirstItemActive();
}
this.attachToOverlay();
this.setActiveOption();
this.cd.markForCheck();
}
}
Expand Down Expand Up @@ -787,6 +776,25 @@ export class NbSelectComponent<T> implements AfterViewInit, AfterContentInit, On
this.emitSelected(this.selectionModel.map((opt: NbOptionComponent<T>) => opt.value));
}

protected attachToOverlay() {
if (!this.ref) {
this.createOverlay();
this.subscribeOnPositionChange();
this.createKeyManager();
this.subscribeOnOverlayKeys();
}

this.ref.attach(this.portal);
}

protected setActiveOption() {
if (this.selectionModel.length) {
this.keyManager.setActiveItem(this.selectionModel[ 0 ]);
} else {
this.keyManager.setFirstItemActive();
}
}

protected createOverlay() {
const scrollStrategy = this.createScrollStrategy();
this.positionStrategy = this.createPositionStrategy();
Expand Down

0 comments on commit c8822b2

Please sign in to comment.