# Keyboard Navigation for Blazor Forms: PageControl

URL: https://flexcoreui.com/demo/page-navigation  
Section: Components  
Controls: PageControl, PageNavigationGraph  
Keywords: keyboard navigation, tab order, focus management, access keys, keyboard shortcuts

Make a Blazor form work without a mouse: PageControl sets the Tab order across inputs and grids, with keyboard shortcuts that jump between regions.

## Documentation

### Page

| Name | Type | Default | Description |
|---|---|---|---|
| NavigationGraph | PageNavigationGraph? | null | The focus nodes and their order; the next table. With no graph the page does not take Tab. |
| NavigationMap | PageNavigationMap? | null | Older linear form: named regions visited in order. Converted to a graph. |
| FocusFirstNodeOnLoad | bool | false | Focus the first target once the page has loaded, retried over a few renders until a grid has rows; never takes focus the user already placed inside the page region. |
| EnableZoomShortcuts | bool | true | With a ZoomService registered on the host, Ctrl with plus, minus and zero zoom FlexCore text. Off on this page so Ctrl with plus and minus keep the browser's own zoom. |
| ScrollMode | PageScrollMode | Auto | How the region scrolls when its content is larger than its space. Auto turns each scrollbar on only when that axis overflows. |
| MaxHeight | string? | null | Height cap for the scroll container, e.g. 100dvh, when the host layout gives none. |
| ChildContent | RenderFragment? |  | The page content. |

### Node

| Name | Type | Default | Description |
|---|---|---|---|
| Id | string |  | Unique name of the node; Next, Previous and shortcuts refer to it. |
| Selector | string |  | CSS selector of the element or region. |
| Order | int? | null | Position in the Tab order; declaration order when null. |
| Next | string? | null | Node Tab goes to instead of the next in order. |
| Previous | string? | null | Node Shift+Tab goes to instead of the previous in order. |
| Mode | PageNavigationNodeMode | Auto | Which elements are the node's targets: Auto, Element or Descendants. |
| Shortcuts | IReadOnlyList<PageNavigationShortcut>? | null | Keys that jump to or activate the node from anywhere inside the PageControl. |
| Entry | PageNavigationEntry | Directional | Where focus lands when arriving from another node: Directional, First or Last. |

### Shortcut

| Name | Type | Default | Description |
|---|---|---|---|
| Key | string |  | The key as the browser reports it (event.key), compared without case: a letter, or a name such as F2. On a Mac, Option changes the character a letter key types, so an Alt+letter shortcut does not fire there. |
| Modifiers | PageShortcutModifiers | None | Alt, Control, Meta, Shift, combined as flags. |
| Action | PageShortcutAction | Focus | Focus the node's target, or Activate it. |
| AllowInEditor | bool | false | Lets a shortcut without Alt, Control or Meta fire while the user types in a text editor. Shortcuts with one of those always fire. |

### Methods

| Name | Type | Description |
|---|---|---|
| FocusFirstNavigationTargetAsync() | Task<bool> | Puts focus on the first available target again, for example after New or Open. False when the page has no graph. |

### Keys

| Name | Description |
|---|---|
| Tab / Shift+Tab | Next or previous target across the nodes. A graph wraps at the ends unless it is built with wrap: false; this page's is, so Tab past the last switch goes on to the rest of the page. |
| Alt+D, Alt+C, Alt+S | This page's shortcuts: focus the details, the contacts grid or the status switches. |
| Inside the grid | The grid's own keys, except Tab and Shift+Tab: with TabNavigationMode PageControl the grid is one stop, so Tab leaves it from any cell. WrapRowsUntilEdge walks the cells first and leaves at the last one. |

## Examples

### Supplier

```razor
@using Fx.ControlKit
@using Fx.ControlKit.Grid

<ButtonControl CssClass="btn-sm" OnClick="@(() => ShowAndFocus(_index - 1))" Disabled="@(_index <= 0)">Previous</ButtonControl>
<ButtonControl CssClass="btn-sm" OnClick="@(() => ShowAndFocus(_index + 1))" Disabled="@(_index >= _suppliers.Count - 1)">Next</ButtonControl>
<PageControl NavigationGraph="@Graph" FocusFirstNodeOnLoad="true" EnableZoomShortcuts="false" @ref="_page">
    <div class="supplier-head"><strong>@_supplier.Name</strong> <span class="muted">supplier @(_index + 1) of @_suppliers.Count</span></div>
    <section id="supplier-details" class="region">
        <h4>Details <kbd>Alt</kbd>+<kbd>D</kbd></h4>
        <div class="fields">
            <label>Code <TextBoxControl Value="@_supplier.Code" readonly Width="110px" aria-keyshortcuts="Alt+D" /></label>
            <label>Name <TextBoxControl @bind-Value="_supplier.Name" /></label>
            <label>Category <TextBoxControl @bind-Value="_supplier.Category" /></label>
            <label>Address <TextBoxControl @bind-Value="_supplier.Address" /></label>
            <label>City <TextBoxControl @bind-Value="_supplier.City" /></label>
            <label>Country <TextBoxControl @bind-Value="_supplier.Country" /></label>
            <label>Postal code <TextBoxControl @bind-Value="_supplier.PostalCode" Width="110px" /></label>
            <label>Phone <TextBoxControl @bind-Value="_supplier.Phone" Width="150px" /></label>
            <label>Email <TextBoxControl @bind-Value="_supplier.Email" /></label>
        </div>
    </section>
    <section id="supplier-contacts" class="region">
        <h4>Contacts <kbd>Alt</kbd>+<kbd>C</kbd></h4>
        <GridControl TValue="Contact" DataSource="@_contacts" Height="200px" AllowSorting="true"
                     TabNavigationMode="GridTabNavigationMode.PageControl">
            <GridColumnsBase>
                <GridColumn Field="@nameof(Contact.DisplayName)" HeaderText="Contact" Width="180px" />
                <GridColumn Field="@nameof(Contact.Role)" HeaderText="Role" Width="160px" />
                <GridColumn Field="@nameof(Contact.Phone)" HeaderText="Phone" Width="130px" />
                <GridColumn Field="@nameof(Contact.Email)" HeaderText="Email" Width="220px" />
                <GridColumn Field="@nameof(Contact.Active)" HeaderText="Active" Width="80px" Type="ColumnType.Boolean" TextAlign="TextAlign.Center" />
            </GridColumnsBase>
        </GridControl>
    </section>
    <section id="supplier-status" class="region">
        <h4>Status <kbd>Alt</kbd>+<kbd>S</kbd></h4>
        <SwitchControl @bind-Checked="_supplier.Contracted" Label="Contracted" aria-keyshortcuts="Alt+S" />
        <SwitchControl @bind-Checked="_supplier.InsuranceOnFile" Label="Insurance on file" />
        <SwitchControl @bind-Checked="_supplier.SendsShipNotices" Label="Sends advance ship notices" />
    </section>
</PageControl>
```

```csharp
// Three nodes in page order; Alt+letter jumps to each. Each selector is a region, so the details and status nodes take their focusable
// descendants; the grid node enters at its first data cell. No wrap: Tab past the last switch leaves the record for the rest of the page.
private static readonly PageNavigationGraph Graph = new(
[
    new("details", "#supplier-details", Mode: PageNavigationNodeMode.Descendants, Shortcuts: [new("d", PageShortcutModifiers.Alt)]),
    new("contacts", "#supplier-contacts", Entry: PageNavigationEntry.First, Shortcuts: [new("c", PageShortcutModifiers.Alt)]),
    new("status", "#supplier-status", Mode: PageNavigationNodeMode.Descendants, Shortcuts: [new("s", PageShortcutModifiers.Alt)]),
], wrap: false);

// Four suppliers of the Forklift & Found Logistics distribution center and the people to call at each.
private readonly List<Supplier> _suppliers =
[
    new() { Code = "SUP-001", Name = "Simmer Down Stoves", Category = "Camp cooking", Address = "410 Foundry Road", City = "Denver", Country = "United States",
            PostalCode = "80216", Phone = "+1 303 555 0142", Email = "orders@simmerdown.example", Contracted = true, InsuranceOnFile = true, SendsShipNotices = true },
    new() { Code = "SUP-002", Name = "Peg to Differ Supply", Category = "Tent hardware", Address = "27 Anvil Street", City = "Boulder", Country = "United States",
            PostalCode = "80301", Phone = "+1 303 555 0117", Email = "orders@pegtodiffer.example", Contracted = true, InsuranceOnFile = true },
    new() { Code = "SUP-003", Name = "Top It Up Bottle Co.", Category = "Drinkware", Address = "960 Canal Avenue", City = "Salt Lake City", Country = "United States",
            PostalCode = "84104", Phone = "+1 801 555 0164", Email = "orders@topitup.example", InsuranceOnFile = true, SendsShipNotices = true },
    new() { Code = "SUP-004", Name = "Lumen Being Headlamps", Category = "Lighting", Address = "5 Copper Lane", City = "Albuquerque", Country = "United States",
            PostalCode = "87102", Phone = "+1 505 555 0128", Email = "orders@lumenbeing.example", Contracted = true },
];

private static readonly Contact[] AllContacts =
[
    new() { SupplierCode = "SUP-001", DisplayName = "Rubeus Haggle", Role = "Order desk", Phone = "+1 303 555 0143", Email = "rubeus.haggle@simmerdown.example" },
    new() { SupplierCode = "SUP-001", DisplayName = "Minerva McGadget", Role = "Accounts", Phone = "+1 303 555 0144", Email = "minerva.mcgadget@simmerdown.example" },
    new() { SupplierCode = "SUP-002", DisplayName = "Cedric Diggle", Role = "Order desk", Phone = "+1 303 555 0118", Email = "cedric.diggle@pegtodiffer.example" },
    new() { SupplierCode = "SUP-003", DisplayName = "Nymphadora Tonic", Role = "Order desk", Phone = "+1 801 555 0165", Email = "nymphadora.tonic@topitup.example" },
    new() { SupplierCode = "SUP-003", DisplayName = "Filius Flipwick", Role = "Accounts", Phone = "+1 801 555 0166", Email = "filius.flipwick@topitup.example", Active = false },
    new() { SupplierCode = "SUP-004", DisplayName = "Sybil Treeline", Role = "Order desk", Phone = "+1 505 555 0129", Email = "sybil.treeline@lumenbeing.example" },
];

private Supplier _supplier = new();
private List<Contact> _contacts = [];
private int _index;

private PageControl? _page;
protected override void OnInitialized() => Show(0);
// Previous and Next sit outside the PageControl, so focus goes back into the record after them.
private async Task ShowAndFocus(int index)
{
    Show(index);
    await Task.Yield();   // let the new record render first
    if (_page is not null) await _page.FocusFirstNavigationTargetAsync();
}

private void Show(int index)
{
    _index = Math.Clamp(index, 0, _suppliers.Count - 1);
    _supplier = _suppliers[_index];
    _contacts = AllContacts.Where(c => c.SupplierCode == _supplier.Code).ToList();
}

private sealed class Supplier
{
    public string Code { get; init; } = "";
    public string Name { get; set; } = "";
    public string Category { get; set; } = "";
    public string Address { get; set; } = "";
    public string City { get; set; } = "";
    public string Country { get; set; } = "";
    public string PostalCode { get; set; } = "";
    public string Phone { get; set; } = "";
    public string Email { get; set; } = "";
    public bool Contracted { get; set; }
    public bool InsuranceOnFile { get; set; }
    public bool SendsShipNotices { get; set; }
}

// SupplierCode is the Code of the supplier the person works for.
private sealed class Contact
{
    public string SupplierCode { get; init; } = "";
    public string DisplayName { get; init; } = "";
    public string Role { get; init; } = "";
    public string Phone { get; init; } = "";
    public string Email { get; init; } = "";
    public bool Active { get; init; } = true;
}
```

