Skip to main content

LgMonthBox

LgMonthBox<TValue> allows you to select a month (and its year). It is part of the date field family (LgDateBox) from which it inherits all behavior: the calendar opens directly at the month level. The bound type can be a date (DateOnly, DateTime, DateTimeOffset, or nullable) or an int / int? — the value is then the month number (1-12), without a year.

<LgMonthBox Label="#BillingMonth" @bind-Value="_model.BillingMonth" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgDateBox<TValue> → LgInputRenderBase<TValue> → LgInputBase<TValue> → LgAriaComponentBase → LgComponentBase
  • NuGet package: Lagoon.UI

The field suffix is reserved: the component automatically places the calendar icon there (Suffix / SuffixType are overridden at initialization).

Usage​

Demo​

Try this component in the Lagoon showcase.

Simple selection​

BillingPage.razor
<LgMonthBox Label="#BillingMonth" @bind-Value="_model.BillingMonth" />
BillingPage.razor.cs
public partial class BillingPage : LgPage
{
private readonly BillingVm _model = new();

private sealed class BillingVm
{
public DateTime? BillingMonth { get; set; }
}
}

Selection bounds​

Min and Max disable months outside the bounds in the calendar.

PeriodPage.razor
<LgMonthBox Label="#Period"
Min="_minDate"
Max="_maxDate"
@bind-Value="_model.Period" />
PeriodPage.razor.cs
public partial class PeriodPage : LgPage
{
// Current fiscal year: bounds the month selection.
private readonly DateTime _minDate = new(2026, 1, 1);
private readonly DateTime _maxDate = new(2026, 12, 31);

private readonly PeriodVm _model = new();

private sealed class PeriodVm
{
public DateOnly? Period { get; set; }
}
}

Month only (without year)​

Bound to an int?, the component carries only the month number (1-12): year navigation is disabled in the calendar and the display shows only the month.

AnniversaryPage.razor
<LgMonthBox Label="#AnniversaryMonth" @bind-Value="_model.AnniversaryMonth" />
AnniversaryPage.razor.cs
public partial class AnniversaryPage : LgPage
{
private readonly AnniversaryVm _model = new();

private sealed class AnniversaryVm
{
// int? : only the "which month" information is stored, without year.
public int? AnniversaryMonth { get; set; }
}
}

Reacting to value changes​

OnChangingAsync (inherited from LgDateBox) is called before assignment and allows canceling the change (args.Cancel); OnChange is called after.

ClosingPage.razor
<LgMonthBox Label="#ClosingMonth"
OnChangingAsync="OnClosingMonthChangingAsync"
@bind-Value="_model.ClosingMonth" />
ClosingPage.razor.cs
public partial class ClosingPage : LgPage
{
private readonly ClosingVm _model = new();

// Called before the change: refuses an already-validated closing month.
private Task OnClosingMonthChangingAsync(ChangingEventArgs<DateTime?> args)
{
if (args.NewValue < DateTime.Today.AddMonths(-1))
{
args.Cancel = true;
ShowWarning("#ClosingMonthLocked");
}
return Task.CompletedTask;
}

private sealed class ClosingVm
{
public DateTime? ClosingMonth { get; set; }
}
}

Properties​

All component [Parameter] properties, including inherited ones.

NameTypeDefaultDeclared inDescription
AssumeNearbyYearint20LgDateBoxNumber of years in the future during which a two-digit year is assigned to the current century. A value less than 1 disables this behavior.
DefaultDateTimeKindDateTimeKindUnspecifiedLgDateBoxDateTimeKind used to create a new DateTime.
DefaultTimeTimeOnly?nullLgDateBoxTime used to create a new DateTime or DateTimeOffset (midnight if null).
DefaultTimeOffsetTimeSpan?nullLgDateBoxTime offset used to create a new DateTimeOffset (local time zone offset if null).
DisplayFormatstringnullLgDateBoxDisplay format. If null, the short date format of the current culture is used, without the day part (and without the year for an int).
KeyboardDisabledboolfalseLgDateBoxDisables keyboard input: the value can only be chosen from the calendar.
MaxDateTime?nullLgDateBoxLatest selectable month; later months are disabled.
MinDateTime?nullLgDateBoxEarliest selectable month; earlier months are disabled.
OnChangeDisabledboolfalseLgDateBoxDisables the DOM onchange event in favor of oninput (used to prevent errors when the control is removed from rendering).
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>nullLgDateBoxCallback called before value change; the change can be canceled.
OnFocusEventCallback<FocusEventArgs>—LgDateBoxCallback called when the field receives focus.
PlaceholderstringnullLgDateBoxHint text displayed when the field is empty.
WeekStartDayOfWeekMondayLgDateBoxFirst day of the week in the calendar.
PrefixstringnullLgInputRenderBasePrefix displayed in the field.
PrefixTypeInputLabelTypeTextLgInputRenderBasePrefix type.
Suffixstring(calendar icon)LgInputRenderBaseSuffix displayed in the field. Reserved: the component places the calendar icon there.
SuffixTypeInputLabelTypeIconNameLgInputRenderBaseSuffix type. Reserved by the component.
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 input validation error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message below the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content for the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after value change.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to edit the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays the field as read-only.
Requiredbool?nullLgInputBaseRequired field. If null, deduced from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseDisplays the clear button. If null, the application behavior configuration applies.
ResetTextstringnullLgInputBaseText for the clear button.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) for the clear button.
TooltipstringnullLgInputBaseTooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates whether the Tooltip content is in HTML format (otherwise plain text).
ValueTValue—LgInputBaseBound value (@bind-Value): date (DateOnly, DateTime, DateTimeOffset, or nullable) or int / int? (month number).
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

LgMonthBox also consumes parameters automatically provided by ancestor components (you don't have to define them): ParentAuthorizeView (LgAuthorizeView) and the editing context of a parent LgEditForm.

Events​

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

Associated enumerations​

The InputLabelType enumeration (prefix / suffix) is documented on LgDateBox, the base component of the date family.

Best practices / accessibility​

  • Bound to a date, the value carries the first day of the month; bound to an int?, it carries only the month number — choose the type based on whether the year matters or not.
  • Do not set Suffix / SuffixType: they are overridden by the calendar icon at component initialization.
Complete reference

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