InputTime
A time field made of spinbutton segments, with a 12 or 24 hour clock taken from the culture. Posts HH:mm.
Examples
12 and 24 hours
Alarm: 14:30, reminder: none
Razor
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Alarm (24 hours)">
<KlyInputTime @bind-Value="_alarm" Hour12="false" data-testid="alarm" />
</KlyFormField>
<KlyFormField Label="Reminder (12 hours, 15 minute steps)">
<KlyInputTime @bind-Value="_reminder" Hour12="true" Step="15" data-testid="reminder" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="time-state">Alarm: @(_alarm?.ToString("HH:mm") ?? "none"), reminder: @(_reminder?.ToString("HH:mm") ?? "none")</p>
</div>
@code {
private TimeOnly? _alarm = new(14, 30);
private TimeOnly? _reminder;
}Not bound
Without a binding the browser keeps the typed time, even when other parameters change.
Razor
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Pickup time">
<KlyInputTime Value="@(new TimeOnly(9, 0))" Hour12="_hour12" Name="pickup" data-testid="unbound-time" />
</KlyFormField>
<KlyButton Variant="ButtonVariant.Outline" Label="Switch the clock" OnClick="Switch" />
</div>
@code {
private bool _hour12;
private void Switch() => _hour12 = !_hour12;
}In an EditForm
Type digits, use the arrow keys, or Backspace to clear a segment.
Razor
<EditForm Model="Model" FormName="meeting" OnValidSubmit="Save" class="flex w-full max-w-xs flex-col items-start gap-3">
<KlyFormField Label="Meeting starts" Description="Posted as HH:mm." Field="FieldIdentifier.Create(() => Model!.Start)" class="w-full">
<KlyInputTime @bind-Value="Model!.Start" Hour12="false" data-testid="meeting" />
</KlyFormField>
<KlyButton Type="ButtonType.Submit" Label="Schedule" />
@if (_saved)
{
<p role="status" class="text-sm text-(--klyroo-success-text)" data-testid="meeting-saved">Scheduled: @Model!.Start?.ToString("HH:mm")</p>
}
</EditForm>
@code {
[SupplyParameterFromForm(FormName = "meeting")]
private Meeting? Model { get; set; }
private bool _saved;
protected override void OnInitialized() => Model ??= new();
private void Save() => _saved = true;
private sealed class Meeting
{
public TimeOnly? Start { get; set; }
}
}API
KlyInputTime
Time field with hour and minute segments, bindable to a TimeOnly? , in 12 or 24 hour format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the field when it is not inside a KlyFormField with a label. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"primary" |
Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral. |
Disabled |
bool |
false |
Disables the control: it cannot be focused or changed and is not submitted. |
Hour12 |
bool? |
Show an AM/PM segment. Defaults to what the culture's short time pattern uses. | |
Id |
string |
The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one. | |
Name |
string |
Form field name outside an EditForm . Inside one, the name comes from the bound expression. | |
Required |
bool |
false |
Marks the control as required, for the browser and for assistive technology. |
Size |
KlySize? |
Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl. |
|
Step |
int |
1 |
Minutes added or removed by the arrow keys on the minute segment. |
Ui |
InputTimeUi |
Per-instance class overrides of the slots of the input time, see InputTimeUi . They are merged after the theme and the Class parameter wins on the root slot. | |
Value (@bind-Value) |
TimeOnly? |
The value of the control. Bind it with @bind-Value . | |
ValueExpression |
Expression |
The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field. | |
Variant |
FieldVariant |
FieldVariant. |
Look of the field: Outline , Soft , Subtle , Ghost or None . Values: Outline, Soft, Subtle, Ghost, None. |
Ui slots
Ui takes a InputTimeUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyInputTime , after the theme and the app configuration. |
Segment |
Classes merged into the segment slot of KlyInputTime , after the theme and the app configuration. |
Separator |
Classes merged into the separator slot of KlyInputTime , after the theme and the app configuration. |