| 54 | imports: [CdkMonitorFocus], |
| 55 | }) |
| 56 | export class MatDateRangeInput<D> |
| 57 | implements |
| 58 | MatFormFieldControl<DateRange<D>>, |
| 59 | MatDatepickerControl<D>, |
| 60 | MatDateRangePickerInput<D>, |
| 61 | AfterContentInit, |
| 62 | OnChanges, |
| 63 | OnDestroy |
| 64 | { |
| 65 | private _changeDetectorRef = inject(ChangeDetectorRef); |
| 66 | private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef); |
| 67 | private _dateAdapter = inject<DateAdapter<D>>(DateAdapter, {optional: true})!; |
| 68 | private _formField = inject<_MatFormFieldPartial>(MAT_FORM_FIELD, {optional: true}); |
| 69 | |
| 70 | private _closedSubscription = Subscription.EMPTY; |
| 71 | private _openedSubscription = Subscription.EMPTY; |
| 72 | |
| 73 | _startInput!: MatStartDate<D>; |
| 74 | _endInput!: MatEndDate<D>; |
| 75 | |
| 76 | /** Current value of the range input. */ |
| 77 | get value() { |
| 78 | return this._model ? this._model.selection : null; |
| 79 | } |
| 80 | |
| 81 | /** Unique ID for the group. */ |
| 82 | id: string = inject(_IdGenerator).getId('mat-date-range-input-'); |
| 83 | |
| 84 | /** Whether the control is focused. */ |
| 85 | focused = false; |
| 86 | |
| 87 | /** Whether the control's label should float. */ |
| 88 | get shouldLabelFloat(): boolean { |
| 89 | return this.focused || !this.empty; |
| 90 | } |
| 91 | |
| 92 | /** Name of the form control. */ |
| 93 | controlType = 'mat-date-range-input'; |
| 94 | |
| 95 | /** |
| 96 | * Implemented as a part of `MatFormFieldControl`. |
| 97 | * Set the placeholder attribute on `matStartDate` and `matEndDate`. |
| 98 | * @docs-private |
| 99 | */ |
| 100 | get placeholder() { |
| 101 | const start = this._startInput?._getPlaceholder() || ''; |
| 102 | const end = this._endInput?._getPlaceholder() || ''; |
| 103 | return start || end ? `${start} ${this.separator} ${end}` : ''; |
| 104 | } |
| 105 | |
| 106 | /** The range picker that this input is associated with. */ |
| 107 | @Input() |
| 108 | get rangePicker() { |
| 109 | return this._rangePicker; |
| 110 | } |
| 111 | set rangePicker(rangePicker: MatDatepickerPanel<MatDatepickerControl<D>, DateRange<D>, D>) { |
| 112 | if (rangePicker) { |
| 113 | this._model = rangePicker.registerInput(this); |