Web Component

Input Date

Easily create nice looking date and time picker.

Table of contents

Usage

The Input Date component is a web component built from scratch to allow users to easily select date and time. To get started, simply use the <uk-input-date> markup in your HTML code.

Capturing values

There are several ways to capture values from the <uk-input-date> component. The simplest approach is to add a name attribute to the component. When you do this, a hidden input field with the specified name will be automatically generated, allowing you to easily capture the selected value on your server.

Prepopulating values

To prepopulate the Input Date component with an existing value, simply pass the value attribute with a YYYY-MM-DD or YYYY-MM-DDTHH:MM format. To prepopulate with current date and time, just use the today attribute and it will automatically set the current date and time as the default value.

Customize display format

To customize the display format, you can use the following parsing tokens and pass them to the display-format attribute.

InputExampleDescription
YY01Two-digit year
YYYY2001Four-digit year
M1-12Month, beginning at 1
MM01-12Month, 2-digits
MMMJan-DecThe abbreviated month name
MMMMJanuary-DecemberThe full month name
dddMon - SunThe abbreviated weekday name
DDDDMonday - SundayThe full weekday name
D1-31Day of month
DD01-31Day of month, 2-digits
H0-23Hours
HH00-23Hours, 2-digits
h1-12Hours, 12-hour clock
hh01-12Hours, 12-hour clock, 2-digits
m0-59Minutes
mm00-59Minutes, 2-digits
AAM PMPost or ante meridiem, upper-case
aam pmPost or ante meridiem, lower-case
Do1st - 31stDay of Month with ordinal

Position

Because the <uk-input-date> component uses the Drop component under the hood, we can leverage its positioning capabilities and position our dropdown anywhere we want. To position it, just use the drop attribute with your drop options.

Size modifiers

There are several size modifiers available. Just add one of the following classes to the cls attribute to make the input smaller or larger.

ClassDescription
.uk-form-xsmallApplies extra small size.
.uk-form-smallApplies small size.
.uk-form-mediumApplies medium size.
.uk-form-largeApplies large size.

Disable input

To prevent user input, add the disabled attribute to the <uk-input-date> element. This will disable the component, making it impossible for users to enter or modify its value.

Error state

To indicate an error state in the form, simply add the .uk-form-danger class to the cls attribute. This will apply a “danger” state to the component, providing visual feedback to the user.

  • This field is required.

PR

Preventing layout shift

When loading Web Components, there may be a brief delay before the content is fully rendered. This can result in a flash of unstyled content or unprocessed templates. To mitigate this issue, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.

Internationalization

The Input Date component supports internationalization through multiple methods with the following priority order (highest to lowest):

  • Component-level i18n (via i18n attribute or script tag)
  • Global component-specific namespace (via <script id="uk-i18n">)
  • Default values

Since this component uses Calendar and Input Time internally, you can provide i18n values for both components within a single configuration.

Using the i18n attribute

Using a configuration script

PR

Using global i18n

Place this in your document <head> or before any input-date components:

Available i18n options

Input Date specific:

KeyDefaultDescription
button-labelSelect dateAria-label for the date picker button
dialog-labelDate pickerAria-label for the dropdown dialog
selectedselectedText added to button label when date is selected
placeholderSelect a datePlaceholder text when no date is selected
placeholder-with-timeSelect a date and timePlaceholder text when with-time is enabled

Calendar specific (inherited):

KeyDefaultDescription
prev-monthPrevious monthAria-label for the previous month navigation button
next-monthNext monthAria-label for the next month navigation button
prev-yearPrevious yearAria-label for the previous year navigation button
next-yearNext yearAria-label for the next year navigation button
select-monthSelect monthAria-label for the month dropdown selector
select-yearSelect yearAria-label for the year input field

Input Time specific (when with-time is enabled):

KeyDefaultDescription
amAMText for AM period
pmPMText for PM period
hour-labelHourAria-label for hour input
minute-labelMinuteAria-label for minute input
meridiem-labelAM/PMAria-label for AM/PM toggle button
time-labelTimeAria-label for time input group
hour-placeholderHHPlaceholder for hour input
minute-placeholderMMPlaceholder for minute input

Custom classes

The Input Date component supports custom CSS classes through the cls attribute. This allows you to style specific elements within the date picker without modifying the component’s internal structure.

Using simple string format

Apply a class to the default element (button):

Using JSON object format

Target specific elements within the input date:

Using configuration script

Available cls targets

TargetDescription
containerThe main wrapper container for the entire component
buttonThe clickable button that opens the date picker
button-textThe text span inside the button showing selected date
iconThe icon element inside the button
dropdownThe dropdown container holding calendar and time inputs
calendarThe calendar component within the dropdown
time-wrapperThe wrapper for time input (when with-time is enabled)
timeThe time input component (when with-time is enabled)

Custom inline styles

The Input Date component supports custom inline styles through the stl attribute. This allows you to apply specific CSS styles to individual elements within the date picker.

Using simple string format

Apply styles to the default element (button):

Using JSON object format

Target specific elements with custom styles:

Using configuration script

Available stl targets

The stl attribute supports the same targets as the cls attribute. See the Available cls targets table above for a complete list of targetable elements.

Custom icons

The Input Date component allows you to customize the calendar icon through the template system:

Available icon keys

KeyDescription
calendarCalendar icon displayed in the button

Attributes

The following attributes are available for this component:

NameTypeDefaultDescription
todayBooleanfalseAutomatically sets today as the initial selected date.
jumpableBooleanfalseEnables month dropdown and year input for quick date navigation in the calendar.
starts-withNumber0 (Sunday)Sets the starting day of the week. 0 for Sunday, 1 for Monday.
disabled-datesStringComma-separated list of dates to disable. Dates must be in format YYYY-MM-DD.
marked-datesStringComma-separated list of dates to mark with indicator. Dates must be in format YYYY-MM-DD.
view-dateStringCurrent dateSets the initial view date of the calendar. Must be in format YYYY-MM-DD.
minStringSets the minimum selectable date (inclusive). Must be in format YYYY-MM-DD.
maxStringSets the maximum selectable date (exclusive). Must be in format YYYY-MM-DD.
weekday-formatStringshortFormat for weekday labels: long, short, or narrow.
langStringen-usLocale string for date formatting (e.g., “en-US”, “fr-FR”, “de-DE”).
display-formatStringMMMM DD, YYYYDisplay format for the selected date. See Customize display format for available tokens.
with-timeBooleanfalseEnables time selection alongside date selection.
clockString12hClock format for time input: 12h or 24h. Only used when with-time is enabled.
require-timeBooleanfalseMakes time input required when with-time is enabled.
dropStringmode: click; animation: uk-animation-slide-top-small;Dropdown options. See Drop component for more options.
nameStringName attribute for the hidden input field, enabling form submission.
disabledBooleanfalseDisables the entire component, preventing user interaction.
requiredBooleanfalseMarks the input as required for form validation.
placeholderStringCustom placeholder text. Overrides default i18n placeholder.
valueStringPre-populated value in YYYY-MM-DD or YYYY-MM-DDTHH:MM format.
clsStringCustom CSS classes. Can be a simple string or JSON object for targeting specific elements.
stlStringCustom inline styles. Can be a simple string or JSON object for targeting specific elements.
i18nStringInternationalization strings as JSON object or via configuration script.
force-prevent-rerenderBooleanfalsePrevents component rerendering (useful for HTMX or SPA scenarios).

Events

The Input Date component triggers the following event:

NameDescription
uk-input-date:changeFired when the date or time value changes. Event detail contains {value: string}.