MonthField
Since 0.1.0-alpha.22A 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
<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>
{
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:
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
| Feature | Static | Interactive |
|---|---|---|
| A page of twelve months to choose from | Yes | Yes |
| Binds the 1st of the month, in a DateOnly or DateTime | Yes | Yes |
| Min and Max compare whole months, and are checked again on the server | 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 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'saria-selectedand this month'saria-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
| Press this key | To do this |
|---|---|
| Alt+Down | Open the months |
In the page of months
| Press this key | To do this |
|---|---|
| Left or Right | Move a month (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 a year |
| Enter or Space | Choose it and close |
| Tab or Shift+Tab | Move through the header and the months, 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
- 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.