Skip to content

Commit ba7afb5

Browse files
committed
fix(datepicker): calendar overlapping input when in a fallback position
* Prevents datepickers that are in a fallback position from overlapping their input by adding an offset. * Fixes some inconsistent brace spacing.
1 parent 40d6bcb commit ba7afb5

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/lib/datepicker/datepicker-input.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
275275
return this._formField ? this._formField.underlineRef : this._elementRef;
276276
}
277277

278+
/**
279+
* Determines the offset to be used when the calendar goes into a fallback position.
280+
* Primarily used to prevent the calendar from overlapping the input.
281+
*/
282+
_getPopupFallbackOffset(): number {
283+
return this._formField ? -this._formField._inputContainerRef.nativeElement.clientHeight : 0;
284+
}
285+
278286
// Implemented as part of ControlValueAccessor
279287
writeValue(value: D): void {
280288
this.value = value;

src/lib/datepicker/datepicker.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,28 @@ export class MatDatepicker<D> implements OnDestroy {
369369

370370
/** Create the popup PositionStrategy. */
371371
private _createPopupPositionStrategy(): PositionStrategy {
372+
const fallbackOffset = this._datepickerInput._getPopupFallbackOffset();
373+
372374
return this._overlay.position()
373375
.connectedTo(this._datepickerInput.getPopupConnectionElementRef(),
374376
{originX: 'start', originY: 'bottom'},
375377
{overlayX: 'start', overlayY: 'top'}
376378
)
377379
.withFallbackPosition(
378-
{ originX: 'start', originY: 'top' },
379-
{ overlayX: 'start', overlayY: 'bottom' }
380+
{originX: 'start', originY: 'top'},
381+
{overlayX: 'start', overlayY: 'bottom'},
382+
undefined,
383+
fallbackOffset
380384
)
381385
.withFallbackPosition(
382386
{originX: 'end', originY: 'bottom'},
383387
{overlayX: 'end', overlayY: 'top'}
384388
)
385389
.withFallbackPosition(
386-
{ originX: 'end', originY: 'top' },
387-
{ overlayX: 'end', overlayY: 'bottom' }
390+
{originX: 'end', originY: 'top'},
391+
{overlayX: 'end', overlayY: 'bottom'},
392+
undefined,
393+
fallbackOffset
388394
);
389395
}
390396

src/lib/form-field/form-field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ng-content select="[matPrefix]"></ng-content>
66
</div>
77

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

1111
<span class="mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper">

src/lib/form-field/form-field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
153153
/** Reference to the form field's underline element. */
154154
@ViewChild('underline') underlineRef: ElementRef;
155155
@ViewChild('connectionContainer') _connectionContainerRef: ElementRef;
156+
@ViewChild('inputContainer') _inputContainerRef: ElementRef;
156157
@ViewChild('placeholder') private _placeholder: ElementRef;
157158
@ContentChild(MatFormFieldControl) _control: MatFormFieldControl<any>;
158159
@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;

0 commit comments

Comments
 (0)