Skip to content

Commit

Permalink
fix(datepicker): calendar overlapping input when in a fallback positi…
Browse files Browse the repository at this point in the history
…on (#8099)

* Prevents datepickers that are in a fallback position from overlapping their input by adding an offset.
* Fixes some inconsistent brace spacing.
  • Loading branch information
crisbeto authored and tinayuangao committed Dec 1, 2017
1 parent 27dfd15 commit e5b7afe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/lib/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
return this._formField ? this._formField.underlineRef : this._elementRef;
}

/**
* Determines the offset to be used when the calendar goes into a fallback position.
* Primarily used to prevent the calendar from overlapping the input.
*/
_getPopupFallbackOffset(): number {
return this._formField ? -this._formField._inputContainerRef.nativeElement.clientHeight : 0;
}

// Implemented as part of ControlValueAccessor
writeValue(value: D): void {
this.value = value;
Expand Down
14 changes: 10 additions & 4 deletions src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,28 @@ export class MatDatepicker<D> implements OnDestroy {

/** Create the popup PositionStrategy. */
private _createPopupPositionStrategy(): PositionStrategy {
const fallbackOffset = this._datepickerInput._getPopupFallbackOffset();

return this._overlay.position()
.connectedTo(this._datepickerInput.getPopupConnectionElementRef(),
{originX: 'start', originY: 'bottom'},
{overlayX: 'start', overlayY: 'top'}
)
.withFallbackPosition(
{ originX: 'start', originY: 'top' },
{ overlayX: 'start', overlayY: 'bottom' }
{originX: 'start', originY: 'top'},
{overlayX: 'start', overlayY: 'bottom'},
undefined,
fallbackOffset
)
.withFallbackPosition(
{originX: 'end', originY: 'bottom'},
{overlayX: 'end', overlayY: 'top'}
)
.withFallbackPosition(
{ originX: 'end', originY: 'top' },
{ overlayX: 'end', overlayY: 'bottom' }
{originX: 'end', originY: 'top'},
{overlayX: 'end', overlayY: 'bottom'},
undefined,
fallbackOffset
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/form-field/form-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ng-content select="[matPrefix]"></ng-content>
</div>

<div class="mat-input-infix mat-form-field-infix">
<div class="mat-input-infix mat-form-field-infix" #inputContainer>
<ng-content></ng-content>

<!--
Expand Down
1 change: 1 addition & 0 deletions src/lib/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
/** Reference to the form field's underline element. */
@ViewChild('underline') underlineRef: ElementRef;
@ViewChild('connectionContainer') _connectionContainerRef: ElementRef;
@ViewChild('inputContainer') _inputContainerRef: ElementRef;
@ViewChild('label') private _label: ElementRef;
@ContentChild(MatFormFieldControl) _control: MatFormFieldControl<any>;
@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;
Expand Down

0 comments on commit e5b7afe

Please sign in to comment.