@progress/kendo-angular-dateinputs
Version:
Kendo UI for Angular Date Inputs Package - Everything you need to add date selection functionality to apps (DatePicker, TimePicker, DateInput, DateRangePicker, DateTimePicker, Calendar, and MultiViewCalendar).
110 lines (109 loc) • 5.21 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Directive, ElementRef, Input, Renderer2, NgZone } from '@angular/core';
import { cloneDate, isEqual } from '@progress/kendo-date-math';
import { DateInputComponent } from '../dateinput/dateinput.component';
import { DateRangeInput } from './date-range-input';
import { DateRangeService } from './date-range.service';
import { EMPTY_SELECTIONRANGE } from '../calendar/models/selection-range.interface';
import { clampRange, isInRange } from '../util';
import { attributeNames } from '../common/utils';
import * as i0 from "@angular/core";
import * as i1 from "./date-range.service";
import * as i2 from "../dateinput/dateinput.component";
/**
* Represents a directive that manages the start selection range for date range inputs.
*
* You can use the DateRangeStartInputDirective only with a DateInput component.
*
* @example
* ```typescript
* @Component({
* selector: 'my-app',
* template: `
* <kendo-daterange>
* <kendo-dateinput kendoDateRangeStartInput [(value)]="startDate"></kendo-dateinput>
* <kendo-dateinput kendoDateRangeEndInput [(value)]="endDate"></kendo-dateinput>
* </kendo-daterange>
* `
* })
* export class AppComponent {
* public startDate: Date = new Date();
* public endDate: Date = new Date();
* }
* ```
*
* @remarks
* Applied to: {@link DateInputComponent}
*/
export class DateRangeStartInputDirective extends DateRangeInput {
rangeService;
dateInput;
renderer;
/**
* Specifies when the component automatically corrects invalid date ranges.
* When the start date is greater than the end date, the component fixes the range to a single date either on input change or on blur ([see example](slug:autocorrect_daterange#toc-input-directives)).
*
* By default, the component does not perform any auto-correction.
*
*/
autoCorrectOn;
/**
* Determines how the calendar navigates when you focus on the input.
* When you set `navigateCalendarOnFocus` to `true`, the calendar moves to the value of the focused input.
* When you set it to `false`, the calendar shows the last selected date.
*
* @default false
*/
navigateCalendarOnFocus = false;
constructor(rangeService, dateInput, element, renderer, zone) {
super('start', rangeService, dateInput, element, renderer, zone);
this.rangeService = rangeService;
this.dateInput = dateInput;
this.renderer = renderer;
}
ngOnInit() {
this.rangeService.registerStartInput(this.dateInput);
super.init();
this.dateInput.pickerType = 'daterangestart';
}
ngAfterViewInit() {
this.renderer.setAttribute(this.dateInput.inputElement, attributeNames.ariaExpanded, 'false');
}
ngOnDestroy() {
super.destroy();
}
getRange(value, correctOn) {
const { min, max } = this.dateInput;
if (!isInRange(value, min, max)) {
return null;
}
const { end } = this.rangeService.selectionRange || EMPTY_SELECTIONRANGE;
const shouldClamp = this.autoCorrectOn === correctOn && end && value > end;
return shouldClamp ? clampRange(value) : { start: cloneDate(value), end };
}
updateInputValue(range) {
const { start } = range || EMPTY_SELECTIONRANGE;
const { min, max } = this.dateInput;
if (isEqual(this.dateInput.value, start) || !isInRange(start, min, max)) {
return;
}
this.dateInput.writeValue(cloneDate(start));
this.dateInput.notify();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DateRangeStartInputDirective, deps: [{ token: i1.DateRangeService }, { token: i2.DateInputComponent }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: DateRangeStartInputDirective, isStandalone: true, selector: "[kendoDateRangeStartInput]", inputs: { autoCorrectOn: "autoCorrectOn", navigateCalendarOnFocus: "navigateCalendarOnFocus" }, usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DateRangeStartInputDirective, decorators: [{
type: Directive,
args: [{
selector: '[kendoDateRangeStartInput]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i1.DateRangeService }, { type: i2.DateInputComponent }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }]; }, propDecorators: { autoCorrectOn: [{
type: Input
}], navigateCalendarOnFocus: [{
type: Input
}] } });