Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datepicker): calendar overlapping input when in a fallback position #8099

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -369,22 +369,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