Table of Contents

Class TwTimePicker

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a time picker component that allows users to select and edit time values, supporting both 12-hour and 24-hour formats.

public class TwTimePicker : TwPopoverPickerComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable
Inheritance
TwTimePicker
Implements
Inherited Members

Remarks

Use the TwTimePicker component to provide an interactive UI for selecting time values in Blazor applications. The component supports two-way binding for the selected TimeOnly value and can be configured to display time in either 12-hour (AM/PM) or 24-hour format.

Constructors

TwTimePicker()

Initializes a new instance of the TwTimePicker class.

public TwTimePicker()

Properties

Is12HourFormat

Gets or sets a value indicating whether the time should be displayed in 12-hour format.

[Parameter]
public bool? Is12HourFormat { get; set; }

Property Value

bool?

Remarks

Set this property to true to use 12-hour time representation (with AM/PM); otherwise, 24-hour format will be used.

Placeholder

The placeholder text to display when no time is selected. Defaults to the localized TimePicker_Placeholder text ("Select a time").

[Parameter]
public string? Placeholder { get; set; }

Property Value

string

SelectedTime

The selected time value.

[Parameter]
public TimeOnly SelectedTime { get; set; }

Property Value

TimeOnly

SelectedTimeChanged

The selected bound time value.

[Parameter]
public EventCallback<TimeOnly> SelectedTimeChanged { get; set; }

Property Value

EventCallback<TimeOnly>

SelectedTimeExpression

Gets or sets the expression that identifies the bound value. Set automatically by @bind-SelectedTime, it lets an enclosing EditForm or TwForm validate the property the field edits.

[Parameter]
public Expression<Func<TimeOnly>>? SelectedTimeExpression { get; set; }

Property Value

Expression<Func<TimeOnly>>

Step

Gets or sets the step, in minutes, that the picker's step buttons and Arrow Up/Arrow Down move the time by. Steps under an hour move the minutes (e.g. 15 gives :00, :15, :30, :45); steps of an hour or more move the hours (e.g. 120 steps two hours at a time) and the minutes show as fixed text. Must divide an hour or, for whole hours, a day. Defaults to 1. Typed times are not rounded to the step.

[Parameter]
public int Step { get; set; }

Property Value

int

Value

The string value displayed in the textbox to the user.

[Parameter]
public string? Value { get; set; }

Property Value

string

ValueChanged

The string bound value displayed in the textbox to the user.

[Parameter]
public EventCallback<string> ValueChanged { get; set; }

Property Value

EventCallback<string>

ValueExpression

Gets or sets the expression that identifies the bound text. Set automatically by @bind-Value, it lets an enclosing EditForm or TwForm validate the property the field edits.

[Parameter]
public Expression<Func<string?>>? ValueExpression { get; set; }

Property Value

Expression<Func<string>>

triggerInputRef

Reference to the trigger textfield's actual <input> element, supplied by derived pickers (TwDatePicker, TwTimePicker) that render a TwTextfield<T> trigger. Used by OnIconClickAsync() to focus that element directly when the browser's native picker is in use.

protected override ElementReference? triggerInputRef { get; }

Property Value

ElementReference?

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

CreateFieldIdentifier()

Creates the identifier of the model property the field's value is bound to. Input components override this to build it from their value expression (supplied by @bind-Value).

protected override FieldIdentifier? CreateFieldIdentifier()

Returns

FieldIdentifier?

The field identifier, or null when the value is not bound to a property.

OnAfterRenderAsync(bool)

Determines, via PreferNativePicker or JS-based device detection, whether the browser's native time picker should be used instead of the custom popover, then re-renders if that changes the input's format/type.

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

Remarks

The native <input type="time"> control always renders using the device's own locale/region setting (e.g. iOS's "24-Hour Time" toggle) and cannot be forced into a specific 12/24-hour display - so auto-detection only opts into the native picker when the caller hasn't requested a specific 12-hour display via Is12HourFormat, otherwise the custom popover (which does honor it) is used instead. An explicit PreferNativePicker still always wins, since that's a deliberate opt-in that accepts the native control's device-driven format.

OnParametersSetAsync()

Method invoked when the component has received parameters from its parent in the render tree, and the incoming values have been assigned to properties.

protected override Task OnParametersSetAsync()

Returns

Task

A Task representing any asynchronous operation.