YearField
Since 0.1.0-alpha.22A 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
<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>
{
[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:
izzy add component YearField --at <file>:<line>Mode support
| Feature | Static | Interactive |
|---|---|---|
| A page of twelve years beside the input | Yes | Yes |
| Binds an int | Yes | Yes |
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
inputwith alabellinked to it. - The page of years is a
grid, named by its span, with the chosen year'saria-selectedand this year'saria-current. Its button is named "Choose year" (ChooseLabel). - Label, hint and errors work as in
TextField.
Keyboard navigation
In the year field
| Press this key | To do this |
|---|---|
| Alt+Down | Open the years |
In the page of years
| Press this key | To do this |
|---|---|
| Left or Right | Move a year (reversed in right-to-left) |
| Up or Down | Move a row |
| Home or End | Go to the start or end of the row |
| Page Up or Page Down | Move twelve years |
| Enter or Space | Choose it and close |
| Tab or Shift+Tab | Move through the header and the years, and close past either end |
| Escape | Close without changing the value |
Parameters
| Prop | Type | Default |
|---|---|---|
ReadOnlyMakes the field read-only: it can be focused, and it still posts. | bool | false |
MinThe earliest value. | TValue | computed |
MaxThe latest value. | TValue | computed |
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. | bool | false |
ClearableA button in the field that empties it, for a nullable value, there while it holds something. | bool | false |
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? |
Plus 28 field props.
Full APISee 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.