Pagination

Page navigation controls for paginated content

The Pagination component provides navigation controls for moving between pages of content. It displays page numbers, previous/next buttons, and handles page state.

Installation

bash
shellui add pagination

Basic Usage

<Pagination CurrentPage="@currentPage"
            CurrentPageChanged="@((page) => currentPage = page)"
            TotalPages="10" />

@code {
    private int currentPage = 1;
}

With Content

Combine pagination with a data list:

Item 1

Description for item 1

Item 2

Description for item 2

Item 3

Description for item 3

<div class="space-y-4">
  @foreach (var item in GetPagedItems())
  {
    <div class="rounded-md border p-4">
      <h3 class="font-medium">@item.Title</h3>
      <p class="text-sm text-muted-foreground">@item.Description</p>
    </div>
  }
</div>

<Pagination CurrentPage="@currentPage"
            CurrentPageChanged="@((page) => currentPage = page)"
            TotalPages="@totalPages" />

@code {
    private record Item(string Title, string Description);

    private const int pageSize = 3;
    private int currentPage = 1;
    private int totalPages => (int)Math.Ceiling(allItems.Count / (double)pageSize);

    private readonly List<Item> allItems = Enumerable.Range(1, 15)
        .Select(i => new Item($"Item {i}", $"Description for item {i}"))
        .ToList();

    private List<Item> GetPagedItems() => allItems
        .Skip((currentPage - 1) * pageSize)
        .Take(pageSize)
        .ToList();
}

Dynamic Page Count

Calculate total pages from data:

<Pagination CurrentPage="@currentPage"
            CurrentPageChanged="@HandlePageChange"
            TotalPages="@((int)Math.Ceiling((double)totalItems / pageSize))" />

@code {
    private int currentPage = 1;
    private int totalItems = 95;
    private int pageSize = 10;

    private async Task HandlePageChange(int page)
    {
        currentPage = page;
        await LoadData();
    }

    private async Task LoadData()
    {
        // Fetch data for current page
    }
}

Custom Styling

<Pagination CurrentPage="@currentPage"
            CurrentPageChanged="@((page) => currentPage = page)"
            TotalPages="20"
            Class="justify-center" />

@code {
    private int currentPage = 1;
}

API Reference

Property Type Default Description
CurrentPage int 1 The active page number
CurrentPageChanged EventCallback<int> — Callback when page changes
TotalPages int 1 Total number of pages
ClassName string? null Additional CSS classes

Accessibility

The Pagination component includes:

  • nav element with aria-label="pagination"
  • aria-current="page" on the active page
  • Keyboard navigable with Tab and Enter
  • Previous/Next buttons with aria-label
  • Disabled state for first/last page boundaries

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.