Skip to main content

LgTimeBox

LgTimeBox<TValue> allows you to input a time, via the keyboard (input mask) or through an interactive clock (clock picker). The bound value is a DateTime (only the time portion is modified) or a TimeSpan — or their nullable versions.

<LgTimeBox Label="#StartTime" @bind-Value="_model.StartTime" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgInputBase<TValue> → LgAriaComponentBase → LgComponentBase
  • NuGet Package: Lagoon.UI

Usage​

Demo​

Try this component in the Lagoon showcase.

Simple input​

By default, the interactive clock is displayed on focus and seconds are ignored (format HH:mm). The default Placeholder is then "HH:MM".

ShiftPage.razor
<LgTimeBox Label="#StartTime" @bind-Value="_model.StartTime" />
ShiftPage.razor.cs
public partial class ShiftPage : LgPage
{
// Model being edited: TimeSpan? for a duration/time of day without date part.
private readonly ShiftVm _model = new();

private sealed class ShiftVm
{
public TimeSpan? StartTime { get; set; }
}
}

Seconds input​

IgnoreSeconds="false" changes the format to HH:mm:ss. In this mode (as when ShowClockPicker="false"), the interactive clock is replaced by a keyboard input mask.

ChronoPage.razor
<LgTimeBox Label="#PreciseTime"
IgnoreSeconds="false"
@bind-Value="_model.PreciseTime" />

@* Mask input only, no clock. *@
<LgTimeBox Label="#AlarmTime"
ShowClockPicker="false"
@bind-Value="_model.AlarmTime" />
ChronoPage.razor.cs
public partial class ChronoPage : LgPage
{
private readonly ChronoVm _model = new();

private sealed class ChronoVm
{
public TimeSpan? PreciseTime { get; set; }
public TimeSpan? AlarmTime { get; set; }
}
}

Time of a DateTime​

When bound to a DateTime, the component only modifies the time portion: the date part of the existing value is preserved (today's date is used if the value is empty).

AppointmentPage.razor
<LgDateBox Label="#AppointmentDate" @bind-Value="_model.Appointment" />
<LgTimeBox Label="#AppointmentTime"
OnChangingAsync="OnTimeChangingAsync"
@bind-Value="_model.Appointment" />
AppointmentPage.razor.cs
public partial class AppointmentPage : LgPage
{
private readonly AppointmentVm _model = new();

// Called before the change: refuses appointments outside business hours.
private Task OnTimeChangingAsync(ChangingEventArgs<DateTime?> args)
{
if (args.NewValue is DateTime value && (value.Hour < 8 || value.Hour >= 18))
{
args.Cancel = true;
ShowWarning("#OutsideOpeningHours");
}
return Task.CompletedTask;
}

private sealed class AppointmentVm
{
public DateTime? Appointment { get; set; }
}
}

Properties​

All [Parameter] properties of the component, including inherited ones.

NameTypeDefaultDeclared inDescription
IgnoreSecondsbooltrueLgTimeBoxIgnores seconds (format HH:mm). When false, the format becomes HH:mm:ss and the interactive clock is replaced by the input mask.
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>nullLgTimeBoxCallback invoked before the value changes; the change can be cancelled.
OnFocusEventCallback<FocusEventArgs>—LgTimeBoxCallback invoked when the field receives focus.
PlaceholderstringnullLgTimeBoxHint text displayed when the field is empty ("HH:MM" by default when the clock is active and seconds are ignored).
ShowClockPickerbooltrueLgTimeBoxShows the interactive clock on focus (only when IgnoreSeconds is true; otherwise the input mask is used).
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgInputBaseAdditional HTML attributes applied to the rendered element.
AutoFocusboolfalseLgInputBaseGives focus to the field on first render.
ConfirmationMessagestringnullLgInputBaseConfirmation message displayed before applying a value change.
ContainerIInputContainer<TValue>nullLgInputBaseInternal use: attaches a GridView cell to the field.
CssClassstringnullLgInputBaseAdditional CSS classes.
DisabledboolfalseLgInputBaseDisables the field.
DisplayNamestringnullLgInputBaseField name used in validation error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message below the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content for the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback invoked after the value changes.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback invoked when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to modify the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays the field as read-only.
Requiredbool?nullLgInputBaseRequired field. If null, inferred from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseShows the clear button. If null, the application's behavior configuration applies.
ResetTextstringnullLgInputBaseText of the clear button.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) of the clear button.
TooltipstringnullLgInputBaseTooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates whether the Tooltip content is in HTML format (otherwise plain text).
ValueTValue—LgInputBaseBound value (@bind-Value), of type DateTime(?) or TimeSpan(?).
ValueChangedEventCallback<TValue>—LgInputBaseCallback for updating the bound value.
ValueExpressionExpression<Func<TValue>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

LgTimeBox also consumes parameters automatically provided by ancestor components (you do not need to define them): ParentAuthorizeView (LgAuthorizeView) and the edit context of a parent LgEditForm.

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>Before the value changes; args.Cancel = true cancels the change.
OnChangeEventCallback<ChangeEventArgs>After the value changes.
OnFocusEventCallback<FocusEventArgs>When the field receives focus.
OnResetEventCallback<ChangeEventArgs>When the field is reset by the clear button.

Best practices / accessibility​

  • Use TimeSpan? for a "pure" time (without date); reserve DateTime for cases where the same model carries both date and time (often paired with a LgDateBox bound to the same property).
  • The interactive clock does not handle seconds: IgnoreSeconds="false" automatically switches to the input mask.
Complete reference

All parameters (including inherited ones): API Reference — LgTimeBox.