Skip to content

Commit

Permalink
fix(module:auto-complete): reposition when open the first time (#1863)
Browse files Browse the repository at this point in the history
close #1840
  • Loading branch information
hsuanxyz authored and vthinkxie committed Aug 3, 2018
1 parent 92d85f3 commit c80bc8d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/auto-complete/nz-autocomplete-trigger.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,24 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD
if (!this.overlayRef) {
this.portal = new TemplatePortal(this.nzAutocomplete.template, this._viewContainerRef);
this.overlayRef = this._overlay.create(this.getOverlayConfig());
} else {
// 如果没有设置 nzDisplayWith 则使用 Host 元素的宽度
this.overlayRef.updateSize({ width: this.nzAutocomplete.nzWidth || this.getHostWidth() });
}
this.overlayPositionChangeSubscription = this.subscribeOverlayPositionChange();

if (this.overlayRef && !this.overlayRef.hasAttached()) {
this.overlayRef.attach(this.portal);
this.overlayPositionChangeSubscription = this.subscribeOverlayPositionChange();
this.selectionChangeSubscription = this.subscribeSelectionChange();
this.overlayBackdropClickSubscription = this.subscribeOverlayBackdropClick();
this.optionsChangeSubscription = this.subscribeOptionsChange();
}

this.nzAutocomplete.isOpen = this.panelOpen = true;
this.nzAutocomplete.setVisibility();
this.overlayRef.updateSize({ width: this.nzAutocomplete.nzWidth || this.getHostWidth() });
setTimeout(() => {
if (this.overlayRef) {
this.overlayRef.updatePosition();
}
}, 150);
this.resetActiveItem();
if (this.activeOption) {
this.activeOption.scrollIntoViewIfNeeded();
Expand Down

0 comments on commit c80bc8d

Please sign in to comment.