Skip to content

Commit

Permalink
fix(module:overlay): update overlay width when the host component's w…
Browse files Browse the repository at this point in the history
…idth change (#780)

close #779
  • Loading branch information
vthinkxie authored Dec 18, 2017
1 parent 196a12a commit 62fc733
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
7 changes: 0 additions & 7 deletions src/components/datepicker/nz-datepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
HostBinding,
Input,
OnInit,
ViewChild,
Expand Down Expand Up @@ -196,7 +195,6 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
_open = false;
_mode = 'year';
_dropDownPosition = 'bottom';
_triggerWidth = 0;
_value: Date = null;
_disabledDate;
_today = new Date();
Expand Down Expand Up @@ -270,10 +268,6 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
}
}

_setTriggerWidth(): void {
this._triggerWidth = this.trigger.nativeElement.getBoundingClientRect().width;
}

onPositionChange(position: ConnectedOverlayPositionChange): void {
const _position = position.connectionPair.originY === 'bottom' ? 'top' : 'bottom';
if (this._dropDownPosition !== _position) {
Expand Down Expand Up @@ -385,7 +379,6 @@ export class NzDatePickerComponent implements ControlValueAccessor, OnInit {
}
this._mode = this.nzMode === 'day' ? 'year' : 'month';
this._open = true;
this._setTriggerWidth();
}

_closeCalendar(): void {
Expand Down
4 changes: 1 addition & 3 deletions src/components/dropdown/nz-dropdown-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ export class NzDropDownButtonComponent extends NzDropDownComponent implements On
return;
}
if (visible) {
if (!this._triggerWidth) {
this._setTriggerWidth();
}
this._setTriggerWidth();
}
if (this.nzVisible !== visible) {
this.nzVisible = visible;
Expand Down
16 changes: 11 additions & 5 deletions src/components/dropdown/nz-dropdown.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectedOverlayPositionChange, ConnectionPositionPair } from '@angular/cdk/overlay';
import { CdkConnectedOverlay, ConnectedOverlayPositionChange, ConnectionPositionPair } from '@angular/cdk/overlay';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand All @@ -11,7 +11,8 @@ import {
OnInit,
Output,
Renderer2,
ViewEncapsulation,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
Expand Down Expand Up @@ -82,6 +83,7 @@ export class NzDropDownComponent implements OnInit, OnDestroy, AfterViewInit {
@Input() nzTrigger: 'click' | 'hover' = 'hover';
@Output() _visibleChange = new Subject<boolean>();
@Output() nzVisibleChange: EventEmitter<boolean> = new EventEmitter();
@ViewChild(CdkConnectedOverlay) _cdkOverlay: CdkConnectedOverlay;

@Input()
set nzClickHide(value: boolean) {
Expand Down Expand Up @@ -151,13 +153,17 @@ export class NzDropDownComponent implements OnInit, OnDestroy, AfterViewInit {

_setTriggerWidth(): void {
this._triggerWidth = this._nzOrigin.elementRef.nativeElement.getBoundingClientRect().width;
/** should remove after https://github.com/angular/material2/pull/8765 merged **/
if (this._cdkOverlay && this._cdkOverlay.overlayRef) {
this._cdkOverlay.overlayRef.updateSize({
minWidth: this._triggerWidth
});
}
}

_onVisibleChange = (visible: boolean) => {
if (visible) {
if (!this._triggerWidth) {
this._setTriggerWidth();
}
this._setTriggerWidth();
}
if (this.nzVisible !== visible) {
this.nzVisible = visible;
Expand Down
19 changes: 12 additions & 7 deletions src/components/select/nz-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* TODO: rebuild latter
*/
import { DOWN_ARROW, ENTER, TAB } from '@angular/cdk/keycodes';
import { ConnectedOverlayPositionChange } from '@angular/cdk/overlay';
import { CdkConnectedOverlay, ConnectedOverlayPositionChange } from '@angular/cdk/overlay';
import {
forwardRef,
AfterContentChecked,
Expand All @@ -12,7 +12,6 @@ import {
ElementRef,
EventEmitter,
HostListener,
Inject,
Input,
OnInit,
Output,
Expand Down Expand Up @@ -164,12 +163,12 @@ import { NzOptionPipe } from './nz-option.pipe';
export class NzSelectComponent implements OnInit, AfterContentInit, AfterContentChecked, ControlValueAccessor {
private _allowClear = false;
private _disabled = false;
_isOpen = false;
private _isTags = false;
private _isMultiple = false;
private _keepUnListOptions = false;
private _showSearch = false;
_el: HTMLElement;
_isOpen = false;
_prefixCls = 'ant-select';
_classList: string[] = [];
_dropDownClassMap;
Expand Down Expand Up @@ -205,6 +204,7 @@ export class NzSelectComponent implements OnInit, AfterContentInit, AfterContent
@Output() nzScrollToBottom: EventEmitter<boolean> = new EventEmitter();
@Input() nzFilter = true;
@Input() nzMaxMultiple = Infinity;
@ViewChild(CdkConnectedOverlay) _cdkOverlay: CdkConnectedOverlay;

@Input()
set nzAllowClear(value: boolean) {
Expand Down Expand Up @@ -315,9 +315,7 @@ export class NzSelectComponent implements OnInit, AfterContentInit, AfterContent
}
if (isOpen) {
this.scrollToActive();
if (!this._triggerWidth) {
this._setTriggerWidth();
}
this._setTriggerWidth();
}
this._isOpen = isOpen;
this.nzOpenChange.emit(this._isOpen);
Expand Down Expand Up @@ -694,7 +692,8 @@ export class NzSelectComponent implements OnInit, AfterContentInit, AfterContent
// TODO: scrollIntoViewIfNeeded is not a standard API, why doing so?
/* tslint:disable-next-line:no-any */
(scrollPane as any).scrollIntoViewIfNeeded(false);
} catch (e) { }
} catch (e) {
}
}
});
}
Expand All @@ -712,6 +711,12 @@ export class NzSelectComponent implements OnInit, AfterContentInit, AfterContent

_setTriggerWidth(): void {
this._triggerWidth = this._getTriggerRect().width;
/** should remove after after https://github.com/angular/material2/pull/8765 merged **/
if (this._cdkOverlay && this._cdkOverlay.overlayRef) {
this._cdkOverlay.overlayRef.updateSize({
width: this._triggerWidth
});
}
}

_getTriggerRect(): ClientRect {
Expand Down
6 changes: 0 additions & 6 deletions src/components/time-picker/nz-timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ import { NzTimePickerInnerComponent } from './nz-timepicker-inner.component';
export class NzTimePickerComponent extends NzTimePickerInnerComponent {
private _timePickerDisabled = false;
_dropDownPosition = 'bottom';
_triggerWidth = 0;
_positions: ConnectionPositionPair[] = [ ...DEFAULT_DATEPICKER_POSITIONS ];

@ViewChild('trigger') trigger;
Expand All @@ -158,10 +157,6 @@ export class NzTimePickerComponent extends NzTimePickerInnerComponent {
return this._timePickerDisabled;
}

_setTriggerWidth(): void {
this._triggerWidth = this.trigger.nativeElement.getBoundingClientRect().width;
}

onPositionChange(position: ConnectedOverlayPositionChange): void {
const _position = position.connectionPair.originY === 'bottom' ? 'top' : 'bottom';
if (this._dropDownPosition !== _position) {
Expand Down Expand Up @@ -207,7 +202,6 @@ export class NzTimePickerComponent extends NzTimePickerInnerComponent {

_openCalendar(): void {
this._open = true;
this._setTriggerWidth();
setTimeout(_ => {
this._initPosition();
this._inputTimeInstance.nativeElement.setSelectionRange(0, 8);
Expand Down

0 comments on commit 62fc733

Please sign in to comment.