Input Time

Easily create nice looking time input.

Table of contents

Usage

The Input Time component is a web component built from scratch to allow users to easily select time in a 12-hour format, while outputting the selected time in a 24-hour format. To get started, simply use the <uk-input-time> markup in your HTML code.

Capturing values

There are several ways to capture values from the <uk-input-time> 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 Time component with an existing value, simply pass the value attribute with a 24-hour time format. To prepopulate with current time, just use the now attribute and it will automatically set the current time as the default value.

Size modifiers

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

ClassDescription
.uk-form-xsApplies extra small size.
.uk-form-smApplies small size.
.uk-form-mdApplies medium size.
.uk-form-lgApplies large size.

Disable input

To prevent user input, add the disabled attribute to the <uk-input-time> element. This will disable all input fields, making it impossible for users to enter or modify time.

Error state

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

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

Available options

NameDescription
amLets you customize “am”.
pmLets you customize “pm”.

Attributes

The following attributes are available for this component:

NameTypeDefaultDescription
autofocusBooleanfalseAutomatically focuses on the first input field when the component is rendered.
cls-customStringAllows you to add custom CSS classes.
disabledBooleanfalseDisables all input fields, making the entire component read-only.
nameStringDefines the name of the input, allowing you to capture its value on your server.
nowBooleanfalseAutomatically set the current time as the default value.
valueStringA time in 24-hour format that will be prepopulated in the input field.

Events

The Input Time component triggers the following events on elements with this component attached:

NameDescription
uk-input-time:inputFired after the value has changed, providing an opportunity to respond to user input.
Customize

Customize your Franken UI experience.