P11MonthPicker Component
P11MonthPicker component provides a native HTML-based month input, leveraging the browser's <input type="month"> element. It offers a straightforward and accessible way for users to select a month and year, with options for min/max month constraints and seamless integration with Blazor's validation system.Basic Month Picker
A simple month picker with default settings.
Current Month: not set
Implementation
<h2 class="mb-3">Basic Month Picker</h2>
<p>A simple month picker with default settings.</p>
<P11MonthPicker Label="Project Start Month"
Description="Select the project's start month."
@bind-Value="projectStartMonth"
ShowDevelopmentErrors="false" />
<p>Current Month: @(projectStartMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? projectStartMonth = null;
}Month Picker with Initial Value and Formatted Display
Month picker with a predefined value (e.g., Next Month) and additional formatted display.
Current Month: Januar 2026
Implementation
<h2 class="mb-3">Month Picker with Initial Value and Formatted Display</h2>
<p>Month picker with a predefined value (e.g., Next Month) and additional formatted display.</p>
<P11MonthPicker Label="Billing Month"
@bind-Value="billingMonth"
ShowFormattedMonth="true" />
<p>Current Month: @(billingMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? billingMonth = DateTime.Today.AddMonths(1);
}Month Picker with Min/Max Months
Month picker that only allows months in the year 2025.
Current Month: Juni 2025
Implementation
<h2 class="mb-3">Month Picker with Min/Max Months</h2>
<p>Month picker that only allows months in the year 2025.</p>
<P11MonthPicker Label="Budget Month 2025"
Description="Select a month in the year 2025."
MinMonth="@(new DateTime(2025, 1, 1))"
MaxMonth="@(new DateTime(2025, 12, 1))"
@bind-Value="budgetMonth2025" />
<p>Current Month: @(budgetMonth2025?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? budgetMonth2025 = new DateTime(2025, 6, 1);
}Disabled Month Picker
A disabled month picker.
Current Month: Januar 2024
Implementation
<h2 class="mb-3">Disabled Month Picker</h2>
<p>A disabled month picker.</p>
<P11MonthPicker Label="Disabled Report Month"
@bind-Value="disabledReportMonth"
Disabled="true" />
<p>Current Month: @(disabledReportMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? disabledReportMonth = new DateTime(2024, 1, 1);
}Month Picker with Required Validation (Conceptual)
This month picker is conceptually required. Note: For actual validation to work, this component must be placed within an EditForm and use DataAnnotationsValidator. This example demonstrates the binding for a required field.
Current Month: März 2025
Implementation
<h2 class="mb-3">Month Picker with Required Validation (Conceptual)</h2>
<p>This month picker is conceptually required. Note: For actual validation to work, this component must be placed within an <code>EditForm</code> and use <code>DataAnnotationsValidator</code>. This example demonstrates the binding for a required field.</p>
<P11MonthPicker Label="Required Report Month"
@bind-Value="requiredReportMonth"
ValidationFor="@(() => requiredReportMonth)" />
<p>Current Month: @(requiredReportMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? requiredReportMonth = new DateTime(2025, 3, 1);
}Month Picker with Additional Attributes
Month picker with custom attributes and CSS class. Check this in the browser inspector.
Current Month: September 2025
Implementation
<h2 class="mb-3">Month Picker with Additional Attributes</h2>
<p>Month picker with custom attributes and CSS class. Check this in the browser inspector.</p>
<P11MonthPicker Label="Month with Extra Attributes"
@bind-Value="extraMonth"
@attributes='new Dictionary<string, object> { { "data-fiscal-period", "Q3" }, { "tabindex", "12" } }'
CssClass="month-highlight" />
<p>Current Month: @(extraMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// Properties for P11MonthPicker examples
private DateTime? extraMonth = new DateTime(2025, 9, 1);
}Month Picker with ValueChanged Event and Separate Value
Demonstrates how to use the Value parameter for initial display and the ValueChanged event to react to changes in the selected month, without using @bind-Value. This is useful if you need to perform custom logic before updating the bound property.
Selected Month: not set
Implementation
<h2 class="mb-3">Month Picker with ValueChanged Event and Separate Value</h2>
<p>Demonstrates how to use the <code>Value</code> parameter for initial display and the <code>ValueChanged</code> event to react to changes in the selected month, without using <code>@@bind-Value</code>. This is useful if you need to perform custom logic before updating the bound property.</p>
<P11MonthPicker Value="monthChangedValue"
ValueChanged="@((DateTime? newMonth) => OnMonthChanged(newMonth))"
Label="Monitor Month Changes"
Description="The month below will update, and a console message will be logged when you select a new month." />
<p>Selected Month: <span class="fw-bold">@(monthChangedValue?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "not set")</span></p>@* You may need the using *@
@* @using System.Globalization *@
@code {
// For ValueChanged event example
private DateTime? monthChangedValue = null;
/// <summary>
/// Event handler for the ValueChanged event of the P11MonthPicker.
/// Updates the bound value and logs the change to the console.
/// </summary>
/// <param name="newMonth">The new nullable DateTime value.</param>
private void OnMonthChanged(DateTime? newMonth)
{
monthChangedValue = newMonth;
Console.WriteLine($"Month changed to: {newMonth?.ToString("MMMM yyyy", CultureInfo.CurrentCulture) ?? "null"}");
}
}Component API
| Parameter | Type | Default | Description |
|---|---|---|---|
Label |
string? |
null |
Gets or sets the label text displayed next to the input field. |
Description |
string? |
null |
Gets or sets a descriptive text displayed below the input field. |
Disabled |
bool |
false |
Gets or sets a value indicating whether the input field is disabled. |
CssClass |
string? |
null |
Gets or sets custom CSS classes to be applied to the component's container div. |
ShowFormattedMonth |
bool |
false |
Gets or sets whether to display the formatted month value next to the picker. |
ShowDevelopmentErrors |
bool |
true |
Gets or sets a value indicating whether development-time configuration errors should be displayed. Defaults to true. Set to false for production environments. |
MinMonth |
DateTime? |
null |
Gets or sets the minimum selectable month. Maps to the HTML 'min' attribute. Only the year and month components of the DateTime are considered for comparison. The day component will be internally set to 1 for HTML value formatting. |
MaxMonth |
DateTime? |
null |
Gets or sets the maximum selectable month. Maps to the HTML 'max' attribute. Only the year and month components of the DateTime are considered for comparison. The day component will be internally set to 1 for HTML value formatting. |
Value |
DateTime? |
null |
Gets or sets the current selected month. Uses two-way binding. The day component of the DateTime will always be normalized to 1 internally. |
ValidationFor |
Expression<Func<DateTime?>>? |
null |
Gets or sets an expression that identifies the field for validation. This is crucial for integrating with Blazor's validation system. |
AdditionalAttributes |
Dictionary<string, object>? |
null |
Captures all unmatched attributes that are not explicitly defined as component parameters. These attributes are applied to the component's container div. |
| Events | |||
ValueChanged |
EventCallback<DateTime?> |
- | Event callback for when the Value changes. Used for two-way binding. |