Tableau UI for Angular
Date Picker
The date picker gives a date input a
Date as its value, for a day or a day and a time.Import
Import TableauUiDatePickerModule and DateValidators from tableau-ui-angular/date-picker. The directive applies to each <input> whose type is date, datetime-local or datetime; the type can't change once set.
Value binding
Bind [(value)]: a Date, or undefined while the input holds no whole date. (valueChange) fires as the user types or picks. A day is midnight, local time; a day and a time is in local time too, and toISOString() gives it in UTC.
In UTC: no date
In UTC: no date
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { TableauUiDatePickerModule } from 'tableau-ui-angular/date-picker';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
@Component({
selector: 'app-date-picker-value-example',
imports: [TableauUiCommonModule, TableauUiDatePickerModule, TableauUiFormFieldModule],
templateUrl: './date-picker-value.example.html',
styleUrl: './date-picker-value.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DatePickerValueExampleComponent {
// A Date, or undefined while the input is empty or holds no whole date
protected readonly $day = signal<Date | undefined>(undefined);
protected readonly $meeting = signal<Date | undefined>(undefined);
// The value is in local time; toISOString() gives it in UTC
protected readonly $dayUtc = computed(() => this.$day()?.toISOString() ?? 'no date');
protected readonly $meetingUtc = computed(() => this.$meeting()?.toISOString() ?? 'no date');
}Reactive forms
Bind [formControl] or formControlName. min and max limit only the browser's picker, so DateValidators.minDate() and maxDate() check a date the user types. The control is touched when the user leaves the input, and a disabled control disables it.
Type a year after 2030 to see an error
Shown in local time
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { Validators } from '@angular/forms';
import { TableauUiCommonModule } from 'tableau-ui-angular/common';
import { DateValidators, TableauUiDatePickerModule } from 'tableau-ui-angular/date-picker';
import { FB, TableauUiFormModule } from 'tableau-ui-angular/form';
import { TableauUiFormFieldModule } from 'tableau-ui-angular/form-field';
// Months count from 0, so 11 is December
const EARLIEST = new Date(2000, 0, 1);
const LATEST_DAY = new Date(2030, 11, 31);
const LATEST_TIME = new Date(2030, 11, 31, 23, 59);
@Component({
selector: 'app-date-picker-forms-example',
imports: [TableauUiCommonModule, TableauUiDatePickerModule, TableauUiFormModule, TableauUiFormFieldModule],
templateUrl: './date-picker-forms.example.html',
styleUrl: './date-picker-forms.example.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DatePickerFormsExampleComponent {
private readonly fb = inject(FB);
// min and max only limit the browser's picker: a typed date outside them is still a value, which the validators
// catch. Each error shows once the user leaves the input, as formHasError waits for it to be touched
protected readonly day = this.fb.control<Date | undefined>(undefined, [Validators.required, DateValidators.minDate(EARLIEST), DateValidators.maxDate(LATEST_DAY)]);
protected readonly meeting = this.fb.control<Date | undefined>(undefined, [Validators.required, DateValidators.minDate(EARLIEST), DateValidators.maxDate(LATEST_TIME)]);
}