From c80bc8de738ad83688e40f7f41722a835ba177e9 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Fri, 3 Aug 2018 17:28:16 +0800 Subject: [PATCH] fix(module:auto-complete): reposition when open the first time (#1863) close #1840 --- .../nz-autocomplete-trigger.directive.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/auto-complete/nz-autocomplete-trigger.directive.ts b/components/auto-complete/nz-autocomplete-trigger.directive.ts index eb570e6200f..2ab6627ae66 100644 --- a/components/auto-complete/nz-autocomplete-trigger.directive.ts +++ b/components/auto-complete/nz-autocomplete-trigger.directive.ts @@ -170,13 +170,11 @@ 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(); @@ -184,6 +182,12 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD 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();