import { KbqDatepickerModule } from '@koobiq/components/datepicker';

KbqCalendarHeader

componentCopy link to KbqCalendarHeader

Default header for KbqCalendar

@Component({ selector: 'kbq-calendar-header', exportAs: 'kbqCalendarHeader' })
class KbqCalendarHeader<D> {
    activeDate = model<D | undefined>();
    maxDate = input<D | null | undefined>();
    minDate = input<D | null | undefined>();
    readonly monthSelected = output<D>();
    readonly yearSelected = output<D>();
    monthNames: MonthName[];
    selectedMonth: number;
    years: number[];
    selectedYear: number;
    get previousDisabled(): boolean;
    get currentDisabled(): boolean;
    get nextDisabled(): boolean;
    onMonthSelected(month: number): void;
    onYearSelected(year: number): void;
    selectCurrentDate(): void;
    selectPreviousMonth(): void;
    selectNextMonth(): void;
}
onMonthSelected()Copy link to onMonthSelected()void

Handles when a new month is selected.

onYearSelected()Copy link to onYearSelected()void

Handles when a new year is selected.

selectPreviousMonth()Copy link to selectPreviousMonth()void

Handles user clicks on the previous button.

selectNextMonth()Copy link to selectNextMonth()void

Handles user clicks on the next button.

KbqDatepicker

componentCopy link to KbqDatepicker

Component responsible for managing the datepicker popup/dialog.

@Component({ selector: 'kbq-datepicker', exportAs: 'kbqDatepicker' })
class KbqDatepicker<D> {
    hasBackdrop = input<boolean | undefined>();
    startAt = input<D | null | undefined>();
    disabled = input<boolean | undefined>();
    opened = input<boolean | undefined>();
    readonly minDate = input<D | null>();
    readonly maxDate = input<D | null>();
    readonly panelClass = input<string | string[]>();
    readonly dateClass = input<(date: D) => KbqCalendarCellCssClasses>();
    readonly backdropClass = input<string>(
        'cdk-overlay-transparent-backdrop'
    );
    readonly yearSelected = output<D>();
    readonly monthSelected = output<D>();
    readonly openedStream = output<void>({ alias: 'opened' });
    readonly closedStream = output<void>({ alias: 'closed' });
    selected: D | null;
    get dateFilter(): (date: D | null) => boolean;
    get value(): D | null;
    readonly disabledChange: Subject<boolean>;
    readonly selectedChanged: Subject<D>;
    id: string;
    popupRef: OverlayRef | null;
    datepickerInput: KbqDatepickerInput<D>;
    select(date: D): void;
    selectYear(normalizedYear: D): void;
    selectMonth(normalizedMonth: D): void;
    registerInput(input: KbqDatepickerInput<D>): void;
    open(): void;
    close(restoreFocus?: boolean): void;
    toggle(): void;
}
startAtinputCopy link to startAtD | null | undefined

The date to open the calendar to initially.

disabledinputCopy link to disabledboolean | undefined

Whether the datepicker pop-up should be disabled.

openedinputCopy link to openedboolean | undefined

Whether the calendar is open.

minDateinputCopy link to minDateD | null

The minimum selectable date.

maxDateinputCopy link to maxDateD | null

The maximum selectable date.

panelClassinputCopy link to panelClassstring | string[]

Classes to be passed to the date picker panel. Supports the same syntax as the [class] binding.

dateClassinputCopy link to dateClass(date: D) => KbqCalendarCellCssClasses

Function that can be used to add custom CSS classes to dates.

localeOverridesinputCopy link to localeOverridesKbqPartialLocaleData | undefined

Localized strings for this element and its subtree, keyed by locale section. Every key is optional at every depth.

yearSelectedoutputCopy link to yearSelectedD

Emits selected year in multiyear view. This doesn't imply a change on the selected date.

monthSelectedoutputCopy link to monthSelectedD

Emits selected month in year view. This doesn't imply a change on the selected date.

openedoutputCopy link to openedvoid

Emits when the datepicker has been opened.

closedoutputCopy link to closedvoid

Emits when the datepicker has been closed.

selectedCopy link to selectedD | null

The currently selected date.

disabledChangeCopy link to disabledChangeSubject<boolean>

Emits when the datepicker is disabled.

selectedChangedCopy link to selectedChangedSubject<D>

Emits new selected date when selected date changes.

idCopy link to idstring

The id for the datepicker calendar.

popupRefCopy link to popupRefOverlayRef | null

A reference to the overlay when the calendar is opened as a popup.

datepickerInputCopy link to datepickerInputKbqDatepickerInput<D>

The input element this datepicker is associated with.

select()Copy link to select()void

Selects the given date

selectYear()Copy link to selectYear()void

Emits the selected year in multiyear view

selectMonth()Copy link to selectMonth()void

Emits selected month in year view

registerInput()Copy link to registerInput()void

Register an input with this datepicker.

Parameters
inputKbqDatepickerInput<D>

The datepicker input to register with this datepicker.

open()Copy link to open()void

Open the calendar.

close()Copy link to close()void

Close the calendar.

KbqDatepickerToggleIconComponent

componentCopy link to KbqDatepickerToggleIconComponent
@Component({ selector: 'kbq-datepicker-toggle-icon' })
class KbqDatepickerToggleIconComponent<D> implements KbqSiblingPopup {
    disabled = input<boolean | undefined>();
    readonly datepicker = input<KbqDatepicker<D>>(undefined, {
        alias: 'for'
    });
    get isAttached(): boolean;
    readonly openedChange: Observable<boolean>;
    open($event: MouseEvent): void;
}
disabledinputCopy link to disabledboolean | undefined

Whether the toggle button is disabled.

forinputCopy link to forKbqDatepicker<D>

Datepicker instance that the button will toggle.

isAttachedCopy link to isAttachedboolean

Whether the calendar is currently on screen. Part of the KbqSiblingPopup contract.

openedChangeCopy link to openedChangeObservable<boolean>

Emits true when the calendar opens and false when it closes. Part of the KbqSiblingPopup contract.

Built on top of the datepicker signal rather than read once, because the instance is bound after the consumers of this stream (a tooltip on the same element subscribes in its constructor) and may be swapped later.

open()Copy link to open()void

Opens the calendar, moving the focus to its input; closes it instead when it was open at the press.

KbqDatepickerInput

directiveCopy link to KbqDatepickerInput

Directive used to connect an input to a KbqDatepicker.

@Directive({
    selector: 'input[kbqDatepicker], input[kbqCalendar]',
    exportAs: 'kbqDatepickerInput'
})
class KbqDatepickerInput<D> implements KbqFormFieldControl<D>, ControlValueAccessor, Validator {
    readonly errorStateMatcher = input<ErrorStateMatcher>();
    readonly placeholder = input<string | undefined>();
    readonly required = input<boolean>(false);
    readonly value = input<D | null | undefined>();
    min = input<D | null | undefined>();
    max = input<D | null | undefined>();
    readonly disabled = input<boolean>(false);
    readonly id = input<string | undefined>();
    readonly incorrectInput = output<void>();
    readonly dateChange = output<KbqDatepickerInputEvent<D>>();
    readonly dateInput = output<KbqDatepickerInputEvent<D>>();
    elementRef: ElementRef<HTMLInputElement>;
    readonly adapter: DateAdapter<D>;
    readonly errorState: Signal<boolean>;
    controlType: string;
    readonly focused: Signal<boolean>;
    datepicker: KbqDatepicker<D>;
    calendar: KbqCalendar<D>;
    dateFilter: (date: D | null) => boolean;
    valueChange: EventEmitter<D | null>;
    disabledChange: EventEmitter<boolean>;
    set kbqDatepicker(value: KbqDatepicker<D>);
    set kbqCalendar(value: KbqCalendar<D>);
    set kbqDatepickerFilter(value: ((date: D | null) => boolean) | undefined);
    set kbqValidationTooltip(value: KbqTooltipTrigger);
    readonly empty: Signal<boolean>;
    get viewValue(): string;
    get ngControl(): any;
    get isReadOnly(): boolean;
    get dateInputFormat(): string;
    onInput: () => void;
    parseOnBlur: () => any;
    onContainerClick(): void;
    focus(): void;
    focusChanged(isFocused: boolean): void;
    onKeyDown(event: KeyboardEvent): void;
    onChange(): void;
    onBlur(): void;
    onPaste(event: ClipboardEvent): void;
    toISO8601(value: D): string;
    updateErrorState(): void;
    getOrigin(): ElementRef;
}
errorStateMatcherinputCopy link to errorStateMatcherErrorStateMatcher

Object used to control when error messages are shown.

placeholderinputCopy link to placeholderstring | undefined

Placeholder of the input. Defaults to the localized date pattern.

requiredinputCopy link to requiredboolean

Whether the input is required.

valueinputCopy link to valueD | null | undefined

The date the input holds: set with [value], by the form control, by typing and by the calendar.

mininputCopy link to minD | null | undefined

The minimum valid date. Drives validation only — including dates typed or pasted into the input — and reports kbqDatepickerMin. The calendar is restricted separately, by minDate on the associated <kbq-datepicker>.

Compared down to the millisecond, not by calendar day: the input keeps the time part of the value it parses, and the comparison is made on wall-clock components rather than on absolute time.

maxinputCopy link to maxD | null | undefined

The maximum valid date. Drives validation only — including dates typed or pasted into the input — and reports kbqDatepickerMax. The calendar is restricted separately, by maxDate on the associated <kbq-datepicker>.

Compared down to the millisecond, not by calendar day: the input keeps the time part of the value it parses, so an upper bound meant to include its whole day has to be the end of that day.

disabledinputCopy link to disabledboolean

Whether the datepicker-input is disabled. Also set by the bound form control.

idinputCopy link to idstring | undefined

Unique id of the element, generated when not provided.

localeOverridesinputCopy link to localeOverridesKbqPartialLocaleData | undefined

Localized strings for this element and its subtree, keyed by locale section. Every key is optional at every depth.

dateChangeoutputCopy link to dateChangeKbqDatepickerInputEvent<D>

Emits when a change event is fired on this <input>.

dateInputoutputCopy link to dateInputKbqDatepickerInputEvent<D>

Emits when an input event is fired on this <input>.

errorStateCopy link to errorStateSignal<boolean>

Whether the input is in an error state.

focusedCopy link to focusedSignal<boolean>

Whether the input has focus.

valueChangeCopy link to valueChangeEventEmitter<D | null>

Emits when the value changes (either due to user input or programmatic change).

disabledChangeCopy link to disabledChangeEventEmitter<boolean>

Emits when the disabled state has changed

kbqDatepickerCopy link to kbqDatepickerKbqDatepicker<D>

The datepicker that this input is associated with.

kbqCalendarCopy link to kbqCalendarKbqCalendar<D>

The calendar that this input is associated with.

kbqDatepickerFilterCopy link to kbqDatepickerFilter((date: D | null) => boolean) | undefined

Function that can be used to filter out dates within the datepicker. undefined removes the filter.

emptyCopy link to emptySignal<boolean>

Whether the input renders no text.

onBlur()Copy link to onBlur()void

Handles blur events on the input.

updateErrorState()Copy link to updateErrorState()void

Refreshes the error state of the input.

getOrigin()Copy link to getOrigin()ElementRef

Returns the ElementRef of the formField if it exists; otherwise, returns the ElementRef of the input.

KbqDatepickerToggleIcon

directiveCopy link to KbqDatepickerToggleIcon

Can be used to override the icon of a kbqDatepickerToggle.

@Directive({ selector: '[kbqDatepickerToggleIcon]' })
class KbqDatepickerToggleIcon {}

KbqDatepickerInputEvent

classCopy link to KbqDatepickerInputEvent

An event used for datepicker input and change events. We don't always have access to a native input or change event because the event may have been triggered by the user clicking on the calendar popup. For consistency, we always use KbqDatepickerInputEvent instead.

class KbqDatepickerInputEvent<D> {
    value: D | null;
    target: KbqDatepickerInput<D>;
    targetElement: HTMLElement;
    constructor(
        target: KbqDatepickerInput<D>,
        targetElement: HTMLElement
    );
}
valueCopy link to valueD | null

The new value for the target datepicker input.

targetCopy link to targetKbqDatepickerInput<D>

Reference to the datepicker input component that emitted the event.

targetElementCopy link to targetElementHTMLElement

Reference to the native input element associated with the datepicker input.

constructor()Copy link to constructor()
Parameters
targetKbqDatepickerInput<D>

Reference to the datepicker input component that emitted the event.

targetElementHTMLElement

Reference to the native input element associated with the datepicker input.

KbqCalendarCellCssClasses

typeCopy link to KbqCalendarCellCssClasses

Extra CSS classes that can be associated with a calendar cell.

type KbqCalendarCellCssClasses = string | string[] | Set<string> | { [key: string]: any };

MonthName

typeCopy link to MonthName
type MonthName = {
    name: string;
    nameShort: string;
    value: number;
    disabled: boolean;
};

KBQ_DATEPICKER_CONFIGURATION

constDeprecatedCopy link to KBQ_DATEPICKER_CONFIGURATION

Use KBQ_DATEPICKER_LOCALE_CONFIGURATION. Will be removed in 22.0.0.

const KBQ_DATEPICKER_CONFIGURATION: InjectionToken<KbqDatepickerLocaleConfiguration>;

KBQ_DATEPICKER_DEFAULT_CONFIGURATION

constDeprecatedCopy link to KBQ_DATEPICKER_DEFAULT_CONFIGURATION

Use KBQ_DATEPICKER_DEFAULT_LOCALE_CONFIGURATION. Will be removed in 22.0.0.

const KBQ_DATEPICKER_DEFAULT_CONFIGURATION: { placeholder: string; dateInput: string; };

KBQ_DATEPICKER_SCROLL_STRATEGY

constCopy link to KBQ_DATEPICKER_SCROLL_STRATEGY

Injection token that determines the scroll handling while the calendar is open. The root default keeps the datepicker usable outside KbqDatepickerModule's injector; providing the token anywhere still wins over it.

const KBQ_DATEPICKER_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;

kbqDatepickerLocaleConfigurationProvider

constCopy link to kbqDatepickerLocaleConfigurationProvider

Utility provider for KBQ_DATEPICKER_LOCALE_CONFIGURATION. Only the strings you pass are overridden; the rest keep following the active locale.

const kbqDatepickerLocaleConfigurationProvider: (
    configuration: KbqDeepPartial<KbqDatepickerLocaleConfiguration>
) => Provider;

MAX_YEAR

constCopy link to MAX_YEAR
const MAX_YEAR: number;
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.