---
title: "Add keyboard-navigable tabs in C#"
url: https://recursiveai.org/oneapp/cookbook/add-keyboard-navigable-tabs-to-desktop-app/
description: "Share a TabsModel across tabs and panels in a C# desktop window. Use the arrow keys to switch panels and skip disabled tabs."
version: "1.1.1"
---

Share one `TabsModel` between the tab buttons and their panels. OneApp runs on [Linux, Windows, and macOS on Apple silicon](https://github.com/recursive-ai-oss/oneapp-csharp/blob/64b0f3162f8c1b7bb766ceae32357442feaa5960/README.md#L62-L68).

```shell
dotnet add package RecursiveAI.OneApp.Kit
dotnet add package RecursiveAI.OneApp
dotnet add package RecursiveAI.OneUI
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```html
<!-- Section: TabsModel in SettingsPage.cs. -->
<Tabs Model="{Section}">
  <TabsList Model="{Section}">
    <TabsTrigger Model="{Section}"
      Value="general">General</TabsTrigger>
    <TabsTrigger Model="{Section}"
      Value="alerts">Alerts</TabsTrigger>
  </TabsList>
  <TabsContent Model="{Section}"
    Value="general">
    Account details
  </TabsContent>
  <TabsContent Model="{Section}"
    Value="alerts">
    Notifications
  </TabsContent>
</Tabs>
```

[The example](https://recursiveai.org/oneapp/cookbook/add-keyboard-navigable-tabs-to-desktop-app/add-keyboard-navigable-tabs-to-desktop-app.zip) is the full program below: unzip it and `dotnet run`.

Press Tab, then Right Arrow to show the Alerts panel. In 1.1.1, selection changed but focus stayed on the original tab. Checked on Linux (X11); not checked on Windows or macOS.

## Full program

OneApp hosts the window, OneApp.Kit supplies the controls, and OneUI compiles the `.html` component.

The zip contains the three files below and `Demo.csproj`. To make the project by hand, create a .NET 10 console app and install the packages above. The example’s project references are:

```xml
<PackageReference Include="RecursiveAI.OneApp" Version="1.1.1" />
<PackageReference Include="RecursiveAI.OneApp.Kit" Version="1.1.1" />
<PackageReference Include="RecursiveAI.OneUI" Version="1.1.0" />
```

OneUI compiles `SettingsPage.html` into the other half of the partial class in `SettingsPage.cs`. Save these files beside the project file.

`SettingsPage.html`:

```html
<Theme>
  <main style="padding: 24px">
    <Tabs Model="{Section}">
      <TabsList Model="{Section}">
        <TabsTrigger Model="{Section}"
                     Value="general">General</TabsTrigger>
        <TabsTrigger Model="{Section}"
                     Value="sync" Disabled="true">Sync</TabsTrigger>
        <TabsTrigger Model="{Section}"
                     Value="alerts">Alerts</TabsTrigger>
      </TabsList>
      <TabsContent Model="{Section}" Value="general">
        Manage your account details.
      </TabsContent>
      <TabsContent Model="{Section}" Value="alerts">
        Manage your notification preferences.
      </TabsContent>
    </Tabs>
  </main>
</Theme>
```

`SettingsPage.cs`:

```csharp
using OneApp.Kit;

public partial class SettingsPage
{
    public TabsModel Section { get; } = new("general");

    protected override void OnMounted() => Section.ValueChanged += Report;
    protected override void OnDisposed() => Section.ValueChanged -= Report;

    private static void Report(string value) => Console.WriteLine($"Tab: {value}");
}
```

`Program.cs` opens the native window:

```csharp
using OneApp;

using var host = AppHost.Create(new AppOptions(new SettingsPage())
{
    Title = "Settings",
    Width = 420,
    Height = 280,
});
host.Run();
```

The full example adds a disabled **Sync** tab between **General** and **Alerts**. Press Tab, then Right Arrow twice: the first press skips Sync and selects Alerts; the second wraps back to General. The terminal prints:

```text
Tab: alerts
Tab: general
```

If selecting a tab leaves the panel blank, check that the trigger and panel use the same `Value` and all the parts use the same model.

![Add keyboard-navigable tabs in C#: example window](https://recursiveai.org/oneapp/images/add-keyboard-navigable-tabs-to-desktop-app/window.png)

## Variations

To stack the triggers and use Up and Down Arrow, change the model initializer in `SettingsPage.cs`:

```csharp
using OneApp.Kit;

public TabsModel Section { get; } = new("general")
{
    Orientation = Orientation.Vertical,
};
```

## Related recipes

- [Build a desktop app with HTML and CSS in C#](https://recursiveai.org/oneapp/cookbook/build-desktop-app-with-html-css/)
- [Customize desktop dark mode and colors](https://recursiveai.org/oneapp/cookbook/theme-desktop-ui-kit/)

## The short answer

Keyboard selection works out of the box: create one `TabsModel`, set its starting value, then pass that instance to `Tabs`, `TabsList`, each `TabsTrigger`, and each `TabsContent`. Give each enabled trigger a panel with the same `Value`. The chosen value decides which panel is rendered.

## How do I switch between desktop tabs with the keyboard?

Tab enters the tab list at the selected trigger. Left and Right Arrow select the previous or next enabled tab and wrap at the ends. Home and End select the first and last enabled tabs. There’s no separate Enter step: changing selection changes the panel immediately.

Selection and keyboard focus aren’t the same thing. In OneApp Kit 1.1.1, Right Arrow changed the panel, `aria-selected`, and which trigger had `tabindex="0"`, but focus stayed on the original trigger. Checked on Linux (X11); not checked on Windows or macOS. If your UI requires the focus indicator to follow the selected tab, account for that behavior when you test it.

## How do I keep a tab and its panel in sync?

Use the value as an identifier, not as the label. In this example `alerts` is the identifier and **Alerts** is what the user reads. `TabsContent` renders a `tabpanel` only when its value is selected. Keep anything that must survive a tab switch in the owning page or model rather than relying on inactive panel content to stay mounted. If you need to respond to a selection in C#, subscribe to `ValueChanged` as the example does. Use a separate model for each independent set of tabs.
