Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

MonthField

Since 0.1.0-alpha.22
Lets the user choose a month, such as a card's expiry, from a page of twelve.

A month field, held as the 1st of the month.

A month

A month field holds the month as its 1st day. On a desktop the user chooses it from a page of twelve; on a phone it's the browser's month input. Min and Max compare whole months, so a Min of March 15 allows March.

Static

Preview

Code

Usage.razor
<Form Model="Model" FormName="month-field-usage" OnValidSubmit="Save" MaxWidth="20.Rem" Grow>
    <MonthField @bind-Value="Model!.Starts" Min="@First" Clearable />
    <Row><Button Submit>Save</Button></Row>
    @if (_saved)
    {
        <Alert Status="Status.Success">Starts @(_starts?.ToString("MMMM yyyy") ?? "unset").</Alert>
    }
</Form>

@code {
    private static readonly DateOnly First = new(2027, 1, 1);

    [SupplyParameterFromForm(FormName = "month-field-usage")]
    private Plan? Model { get; set; }

    // What was saved, not the field: on an interactive page it follows what's chosen.
    private bool _saved;
    private DateOnly? _starts;

    protected override void OnInitialized() => Model ??= new();

    private void Save() => (_saved, _starts) = (true, Model!.Starts);

    public sealed class Plan
    {
        public DateOnly? Starts { get; set; } = new DateOnly(2027, 3, 1);
    }
}

Static: On a desktop, the user chooses the month rather than typing it. On a phone it's the browser's month input.

Add this example to a page with the izzy CLI:

bash
izzy add component MonthField --at <file>:<line>

Details

On a desktop a month is chosen, not typed, and its button shows it, since browsers other than Chromium's have no month input. A phone and UseNative keep the browser's input, and with no script it's the browser's too, a text box with a pattern where it has none. Min and Max compare whole months, so a Min of March 15 allows March. [Range] compares the 1st of the month, so give it a 1st, as a Range starting on March 15 would turn away March.

Mode support

What works in each mode, MonthField
FeatureStaticInteractive
A page of twelve months to choose fromYesYes
Binds the 1st of the month, in a DateOnly or DateTimeYesYes
Min and Max compare whole months, and are checked again on the serverYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Without JavaScript

Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, it's the browser's own month input, a text box taking YYYY-MM where the browser has none.

Accessibility

  • The month's button stands in for the input on a desktop, so it's named by the field's label and the month, and takes the hint and errors.
  • The page of months is a grid, named by its year, with the chosen month's aria-selected and this month's aria-current. Focus goes to the chosen month or this one, and on closing back to the button.
  • Label, hint and errors work as in TextField.

Keyboard navigation

In the month field

MonthField keys, In the month field
Press this keyTo do this
Alt+DownOpen the months

In the page of months

MonthField keys, In the page of months
Press this keyTo do this
Left or RightMove a month (reversed in right-to-left)
Up or DownMove a row
Home or EndGo to the start or end of the row
Page Up or Page DownMove a year
Enter or SpaceChoose it and close
Tab or Shift+TabMove through the header and the months, and close past either end
EscapeClose without changing the value

Parameters

MonthField parameters
PropTypeDefault
ReadOnlyMakes the field read-only: it can be focused, and it still posts.boolfalse
MinThe earliest value.TValuecomputed
MaxThe latest value.TValuecomputed
StartAddonContent attached before the control, outside its border.RenderFragment?
EndAddonContent attached after the control, outside its border.RenderFragment?
UseNativeKeeps the browser's input in place of the library's page to choose from.boolfalse
ClearableA button in the field that empties it, for a nullable value, there while it holds something.boolfalse
ChooseLabelThe name of the button that opens the page, in place of "Choose month" or "Choose year".string?
CultureThe culture for the names of months and days, and for the week.CultureInfo?computed
@bind-ValueThe value, bound with @bind-Value.TValue
DisplayNameThe field's name in validation messages from the input itself, such as a value that can't be parsed.string?

See also

  • YearField: lets the user type a year, or choose it from a page of twelve.
  • DateField: takes a due date, a birthday or an appointment's date and time, typed or picked from a calendar.
  • Calendar: puts a month on the page itself, for picking a day without opening a field.

Connection lost

Rejoining the server…