Skip to content

Tabs: tab list + panels with roles, roving arrow keys, and the panel switch #346

Open

Description

@samitbasu

Both consumers build tab strips by hand: b.segmented plus the app's own match to switch the body. So there are no tab/tabpanel roles, no link between a tab and its panel, and no arrow-key movement between tabs.

Proposal: an owned Tabs widget that keeps segmented's look (or a variant) and adds:

  • role=tablist / tab / tabpanel, with each panel labelled by its tab;
  • roving focus with ←/→ (Home/End), activation on focus or on Enter (an a11y decision for the user);
  • the widget owning the body switch, with the selected value in app state.

The docs site also wants it (Rust/HTML code switchers). Design note first; looks go to the user as candidates.

Activity

  1. added
    v0.1
    consumer
    on Nov 18, 2026
  2. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Design note: Tabs

    Status: proposal for review. No code yet. Every look question and the API shape are yours to decide; I give a recommendation for each.

    Goal (#351): take the "segmented control plus the app's own match" pattern out of the app shells. Add the tab, tab list and tab panel roles, arrow-key movement, and a panel switch the widget owns.

    Where it lives: in crates/eggshell-ui-extras, behind a tabs feature, built only on core's public API. Its style lives in extras, and the shadcn values sit behind the shadcn crate's extras feature, as Markdown's do. Core's public API cannot carry it as it stands today. It needs two small public additions, both described in section 3.


    1. Proposed public API

    use eggshell_ui_extras::tabs::{Activation, TabsExt};
    
    #[derive(Clone, Copy, PartialEq)]
    enum Lang { Rust, Html }
    
    struct App { lang: Lang }            // the selected tab is a plain app field
    
    fn view<'f>(b: &mut Builder<'_, 'f, App>, app: &'f App) {
        b.tabs("lang", app.lang, [(Lang::Rust, "Rust"), (Lang::Html, "HTML")])
            .named("Language")                       // the tab list's accessible name
            .on_change(|app, lang| app.lang = lang)
            .panel(|b, lang| match lang {            // builds the selected panel only
                Lang::Rust => rust_snippet(b, app),
                Lang::Html => html_snippet(b, app),
            });
    }

    The options are anything that implements IntoChoice<T>, the same trait segmented, radio_group and select take. So Choice::new(v, "Label").icon(..).tooltip(..).enablement(..) works unchanged, with no parallel option type.

    The other chain methods:

    Method Purpose
    .activation(Activation::OnFocus | OnEnter) Keyboard activation model (see section 2). The default is your choice (Q1).
    .size(Size) / .enablement(..) As on segmented.
    .list(Tw) / .panel_classes(Tw) Classes merged over the styled list and panel, such as w_full().
    .on_change(..) Required, as for segmented. It is not terminal, because the panel still has to be built.
    `.panel( b, value
    .strip_only() Terminal, the alternative to .panel. Use it when the app places the panel itself (Q4).

    Who owns state. The selected value is app state: a plain T field the app passes in each frame and sets in on_change. This follows the "app state is plain fields" rule, and the widget never stores the selection. The library stores nothing new either: focus is egui's own, and the single Tab stop is derived each frame from current.

    2. Behaviour and keyboard model

    Aspect Proposal
    Roles The list is Role::TabList, named by .named(..). Each tab is Role::Tab with accesskit selected set on the current one. The panel is Role::TabPanel, named by its tab's label (the effect of aria-labelledby), and the tab carries controls → panel id. accesskit 0.25 has all three roles, plus set_controls and set_selected.
    Tab stops The list is one Tab stop: the selected tab, or the first enabled tab when the current value is not among the options. Tab leaves the list for the panel's first focusable item. This is the radio-group rule that eggshell already follows.
    Arrows ←/→ move focus to the previous or next enabled tab and wrap, as in Radix (loop defaults to true). Home and End go to the first and last tab. ↑/↓ do nothing in a horizontal list.
    Activation OnFocus (Radix "automatic", the default): moving focus selects, so on_change runs on each arrow press. OnEnter (Radix "manual"): arrows move focus only, and Enter or Space selects. Click selects in both modes. This is an a11y decision for you (Q1).
    Panel switch The widget owns it. .panel builds exactly the selected panel, so the app's match moves into the closure and the widget emits the tabpanel node around it.
    Lazy vs kept panels Lazy only (Radix's default, which unmounts inactive content). Immediate mode makes "kept" pointless: per-node state outlives the frames that don't declare it. eggshell's scroll viewports in Kept are never pruned, and egui keeps text-edit memory by id. So a returning panel finds its scroll offset and its caret. PR 3 asserts this in a test. A "kept but hidden" panel would need a display:none class that core lacks, and I don't propose adding one.
    Panel focusability Radix gives the panel tabindex=0. Q3 asks whether we do.
    Disabled tabs Skipped by the arrows and drawn in the disabled look, as Choice::enablement already documents.
    Orientation Horizontal only in v1. A vertical list (↑/↓) is a variant of the same nav primitive and stays out until a consumer asks (Q5).

    3. Reuse, and what core must make public

    What the widget reuses:

    • Options: owned::{Choice, IntoChoice}, which are already public.
    • Look: segmented's track and cell classes from Style::segmented (SegmentedStyle), so the default tabs look is the segmented look until you choose otherwise. That is exactly what both consumers show today.
    • Tooltips, enablement, focus ring: the existing public NodeHandle::tooltip, the Enablement look via the classes, and the core focus ring.
    • accesskit extras: controls and selected go through egui's public Context::accesskit_node_builder in a draw closure, the same pattern core's own NodeHandle::expanded uses.

    Why extras cannot build it on today's public API, and the smallest fixes:

    Gap Today Smallest public core primitive
    Roving focus on the page Nav (Menu, Listbox, Grid) is public, but only overlays and virtual lists accept it. radio_group has a private roving implementation (navigate, take_focus_if_asked, and an egui-temp FOCUS_REQUEST that works around egui dropping focus given to a node that is not yet focusable). Doing it a third time in extras is the forked-implementation hazard. NodeHandle::nav(Nav) on a page node, plus Nav::Row(Wrap) (←/→, Home, End, real focus; items are nodes with an item role, here Tab and RadioButton), plus NodeHandle::selected(bool), which sets accesskit selected and marks the group's single Tab stop. radio_group then moves onto it and its private copy is deleted.
    The segmented look as classes Paint::classes and centered are pub(crate), so extras would have to re-derive segmented's class composition. That re-derivation would drift. SegmentedStyle::track(&self, ctx, size, rows) -> Tw and SegmentedStyle::cell(&self, ctx, size, Cell, Enablement) -> Tw: pure methods that segmented itself calls, so both widgets share one composition.

    The widget needs no new #[doc(hidden)] items, no new overlay support and no new clock.

    A rejected alternative is a .tabs() mode on segmented that swaps its roles. It is cheaper, but it gives core a shadcn composite, and the panel would still need extras. Rewriting roles in on_response would be a work-around, and the "fix the API" rule rules it out.

    4. Look decisions for a render round (no picks made)

    I'll render every candidate at real size, in light and dark, next to a panel and a heading:

    1. Variant: the segmented track (shadcn default: bg-muted track, active bg-background shadow-sm), shadcn's line variant (transparent track, 2 px underline under the active tab), or both.
    2. Active tab: fill, shadow, and the dark-mode border-input / bg-input/30 treatment.
    3. Text: inactive colour (shadcn foreground/60, hover → foreground), weight (font-medium), and whether the active tab gets a heavier weight (segmented.selected_weight, which shifts widths).
    4. List width: fit (w-fit) or full width with equal tabs.
    5. Gap between list and panel: shadcn gap-2.
    6. Panel framing: none (shadcn), a card, or a top rule.
    7. Focus ring on a tab, inside the track or overlapping it.
    8. Icon and label spacing and icon size (shadcn gap-1.5, size-4).
    9. Disabled tab look (opacity-50).
    10. Transition of the active fill or underline: none, a cross-fade of fills, or a sliding indicator.
    11. Sizes: whether tabs follow segmented's Size scale.

    5. Breaking changes and PR split

    Breaking changes: none. Everything is additive. The radio-group migration in PR 1 is declared behaviour-preserving, and its tests must not change.

    PR Contents Size
    1 (core) Page-level NodeHandle::nav with Nav::Row(Wrap), NodeHandle::selected, and the single-Tab-stop rule. Moves radio_group onto it and deletes its private roving code. Adds kittest tests through the full dispatch path. M (~400 lines)
    2 (core) SegmentedStyle::track / cell; segmented calls them. Behaviour-preserving, with goldens unchanged. S (~120)
    3 (extras) The tabs feature: TabsExt, roles, controls, activation modes, the panel, and tests (roles, arrows, wrap, disabled skip, Tab-stop, state survival across a switch). M (~450)
    4 (extras + shadcn) Look after the render round: a TabsStyle only if the pick departs from segmented (for example line), its shadcn fill behind extras, and an example for the docs site's Rust/HTML switcher. You try the build before the PR is approved. S–M

    6. Questions for you

    # Question My recommendation
    Q1 Activation: on focus (Radix automatic) or on Enter (manual)? Do we offer both? Offer both, default OnFocus. It matches Radix and eggshell's radio group, and a panel switch is cheap in immediate mode. OnEnter is for panels that are expensive to build.
    Q2 Should Tabs live in extras with the two core primitives (nav on the page with Nav::Row, and the public segmented class methods)? The alternative is a role mode on core's segmented. Extras plus the two primitives. The roving primitive also deletes radio's private copy.
    Q3 Should the panel be a Tab stop (Radix tabindex=0)? Only when it has no focusable content of its own. In v1 that means no, because both consumers' panels hold controls. Revisit for text-only panels.
    Q4 Should the widget always place list and panel together (.panel), or also offer .strip_only() for a list in a toolbar and a panel elsewhere? Both. .strip_only() still sets the roles and needs a panel_id to set controls. Keep it in only if a consumer actually separates the two (one may: its strip sits in a header).
    Q5 Vertical orientation in v1? No. Nav::Column can come later on the same primitive.
    Q6 Default look: identical to segmented, or shadcn's tabs (nearly the same), or line? Render all three. I lean to segmented-identical as the default, so consumers see no visual change on migration.
  3. samitbasu commented on Nov 18, 2026

    @samitbasu
    OwnerAuthor

    Decisions (user, 2026-11-18):

    • Activation: on focus, with an optional .activate_on_enter().
    • Core additions approved: roving Nav::Row (radio_group moves onto it and its private copy is deleted) and segmented's look as public class methods.
    • Default look: identical to segmented.
    • The note's other recommendations stand: the panel isn't a Tab stop in v1; .strip_only() only if a consumer needs it; no vertical tabs in v1.
    • Placement: the widgets crate (One crate: merge eggshell-ui-extras and eggshell-ui-shadcn into eggshell-ui (features for opt-in widgets) #366); extras until the split.
  4. added 2 commits that reference this issue on Nov 18, 2026
  5. samitbasu commented on Nov 20, 2026

    @samitbasu
    OwnerAuthor

    Look decision revisited (user, 2026-11-19). Every eggshell widget names one shadcn component as its source, with no special cases, so automated extraction applies uniformly.

    • Tabs follow tabs.tsx exactly:
      • the list is rounded-lg p-[3px] h-9 on bg-muted;
      • a trigger is rounded-md px-2 py-1 text-sm font-medium, h-[calc(100%-1px)];
      • inactive text is foreground/60, with hover:text-foreground;
      • the active trigger has shadow-sm.
        Cited from the pinned ref (styles/style-vega.css:1320-).
    • The segmented control's declared source is also tabs.tsx's list look, so tabs and segmented stay identical and now both match shadcn exactly. The 4 differences found in extras: the tabs widget, on core's roving nav and the segmented look (#346, PR 3) #440 are fixed for both, a visible change to segmented, shown in PR 4's render round.
    • The importer (Preset: Button matches current shadcn (generated by shadcn-import) #433) generates these later; meanwhile the values are hand-set with citations.
  6. samitbasu commented on Nov 20, 2026

    @samitbasu
    OwnerAuthor

    Track fill decided (user, 2026-11-19, from the rendered candidates): (b) the input fill for the tabs and segmented track. It's the one documented exception to "exactly tabs.tsx": shadcn's bg-muted vanishes on a muted surface (1.00:1). The other three tabs.tsx values stand. Revisit as an automatic surface-aware rule once the cascade pass (#443) exists. Record the exception, with its reason, in the importer's mapping (#433).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    consumerv0.1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions