Skip to content

Commit 0ebc001

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 9e35bf0 commit 0ebc001

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
@@ -273,6 +273,14 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce
273273
return this._formField ? this._formField.underlineRef : this._elementRef;
274274
}
275275

276+
/**
277+
* Determines the offset to be used when the calendar goes into a fallback position.
278+
* Primarily used to prevent the calendar from overlapping the input.
279+
*/
280+
_getPopupFallbackOffset(): number {
281+
return this._formField ? -this._formField._inputContainerRef.nativeElement.clientHeight : 0;
282+
}
283+
276284
// Implemented as part of ControlValueAccessor
277285
writeValue(value: D): void {
278286
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
<!--

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export class MatFormField implements AfterViewInit, AfterContentInit, AfterConte
159159
/** Reference to the form field's underline element. */
160160
@ViewChild('underline') underlineRef: ElementRef;
161161
@ViewChild('connectionContainer') _connectionContainerRef: ElementRef;
162+
@ViewChild('inputContainer') _inputContainerRef: ElementRef;
162163
@ViewChild('label') private _label: ElementRef;
163164
@ContentChild(MatFormFieldControl) _control: MatFormFieldControl<any>;
164165
@ContentChild(MatPlaceholder) _placeholderChild: MatPlaceholder;

0 commit comments

Comments
 (0)