Skip to content

Commit e5b7afe

Browse files
crisbetotinayuangao
authored andcommitted
fix(datepicker): calendar overlapping input when in a fallback position (#8099)
* Prevents datepickers that are in a fallback position from overlapping their input by adding an offset. * Fixes some inconsistent brace spacing.
1 parent 27dfd15 commit e5b7afe

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
@@ -372,22 +372,28 @@ export class MatDatepicker<D> implements OnDestroy {
372372

373373
/** Create the popup PositionStrategy. */
374374
private _createPopupPositionStrategy(): PositionStrategy {
375+
const fallbackOffset = this._datepickerInput._getPopupFallbackOffset();
376+
375377
return this._overlay.position()
376378
.connectedTo(this._datepickerInput.getPopupConnectionElementRef(),
377379
{originX: 'start', originY: 'bottom'},
378380
{overlayX: 'start', overlayY: 'top'}
379381
)
380382
.withFallbackPosition(
381-
{ originX: 'start', originY: 'top' },
382-
{ overlayX: 'start', overlayY: 'bottom' }
383+
{originX: 'start', originY: 'top'},
384+
{overlayX: 'start', overlayY: 'bottom'},
385+
undefined,
386+
fallbackOffset
383387
)
384388
.withFallbackPosition(
385389
{originX: 'end', originY: 'bottom'},
386390
{overlayX: 'end', overlayY: 'top'}
387391
)
388392
.withFallbackPosition(
389-
{ originX: 'end', originY: 'top' },
390-
{ overlayX: 'end', overlayY: 'bottom' }
393+
{originX: 'end', originY: 'top'},
394+
{overlayX: 'end', overlayY: 'bottom'},
395+
undefined,
396+
fallbackOffset
391397
);
392398
}
393399

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)