Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

YearField

Since 0.1.0-alpha.22
Lets the user type a year, or choose it from a page of twelve.

A year field, held in an int.

A year

A year field holds a year in an int: a number input, with a page of twelve years to choose from beside it on a desktop. Min and Max set the earliest and latest year.

Static

Preview

Code

Usage.razor
<Form Model="Model" FormName="year-field-usage" OnValidSubmit="Save" MaxWidth="20.Rem" Grow>
    <YearField @bind-Value="Model!.Year" Label="Model year" Min="2000" Max="2030" />
    <Row><Button Submit>Save</Button></Row>
    @if (_saved)
    {
        <Alert Status="Status.Success">Model year @(_year?.ToString() ?? "unset").</Alert>
    }
</Form>

@code {
    [SupplyParameterFromForm(FormName = "year-field-usage")]
    private Vehicle? Model { get; set; }

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

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

    private void Save() => (_saved, _year) = (true, Model!.Year);

    public sealed class Vehicle
    {
        public int? Year { get; set; }
    }
}

Add this example to a page with the izzy CLI:

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

Mode support

What works in each mode, YearField
FeatureStaticInteractive
A page of twelve years beside the inputYesYes
Binds an intYesYes

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 a number input, with no page of years to choose from.

Accessibility

  • It renders the browser's number input with a label linked to it.
  • The page of years is a grid, named by its span, with the chosen year's aria-selected and this year's aria-current. Its button is named "Choose year" (ChooseLabel).
  • Label, hint and errors work as in TextField.

Keyboard navigation

In the year field

YearField keys, In the year field
Press this keyTo do this
Alt+DownOpen the years

In the page of years

YearField keys, In the page of years
Press this keyTo do this
Left or RightMove a year (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 twelve years
Enter or SpaceChoose it and close
Tab or Shift+TabMove through the header and the years, and close past either end
EscapeClose without changing the value

Parameters

YearField 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

  • MonthField: lets the user choose a month, such as a card's expiry, from a page of twelve.
  • NumberField: lets the user enter a number, with step buttons.
  • DateField: takes a due date, a birthday or an appointment's date and time, typed or picked from a calendar.

Connection lost

Rejoining the server…