UNPKG

@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).

108 lines (107 loc) 5.34 kB
/**----------------------------------------------------------------------------------------- * 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"; /** * A directive which manages the start selection range. * * > You can use the DateRangeStartInputDirective only with a DateInput component. */ export class DateRangeStartInputDirective extends DateRangeInput { rangeService; dateInput; renderer; /** * Specifies the auto-correction behavior. If the start date is greater than the end date, * the directive fixes the date 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; /** * Specifies the navigation behavior of the calendar when the active end is changed on input focus. * When enabled, the calendar navigates to the value of the focused input. Otherwise, the calendar * displays the last picked date. * * By default, the automatic navigation behavior on input focus is disabled. * * @example * ```ts * _@Component({ * selector: 'my-app', * template: ` * <h5>Toggle input focus to see the calendar navigating between range ends.</h5> * <kendo-daterange> * <kendo-dateinput kendoDateRangeStartInput [navigateCalendarOnFocus]="true" [(value)]="start"></kendo-dateinput> * <kendo-dateinput kendoDateRangeEndInput [navigateCalendarOnFocus]="true" [(value)]="end"></kendo-dateinput> * </kendo-daterange> * ` * }) * export class AppComponent { * public start: Date = new Date(2018, 3, 10); * public end: Date = new Date(2018, 10, 20); * } * ``` */ 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 }] } });