Skip to content

extras: the tabs widget, on core's roving nav and the segmented look (#346, PR 3) - #440

Merged
samitbasu merged 7 commits into
mainfrom
tabs-346
Nov 20, 2026
Merged

samitbasu merged 7 commits into
mainfrom
tabs-346

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Part of #346: PR 3 of the design note, the tabs widget in extras. It builds on #368 (roving nav) and #425 (the segmented look as public classes).

What

b.tabs("lang", app.lang, [(Lang::Rust, "Rust"), (Lang::Html, "HTML")])
    .named("Language")
    .on_change(|app: &mut App, lang| app.lang = lang)
    .panel(|b, lang| match lang {
        Lang::Rust => rust_snippet(b),
        Lang::Html => html_snippet(b),
    });
  • A new tabs feature in eggshell-ui-extras. TabsExt::tabs(key, current, options) takes anything IntoChoice<T>, as segmented does, so icons, tooltips, disabled and refused options work unchanged. It is built on core's public API only.
  • The chain:
    • .named(..): the tab list's accessible name.
    • .size(..), .enablement(..): as on segmented, over what the subtree gives (Builder::control_size(), Builder::enablement()).
    • .activate_on_enter(): the arrows move focus only, and Enter or Space selects. By default the arrows select as they move.
    • .list_classes(..) and .panel_classes(..): merged over the list's and the panel's.
    • .on_change(..): required. It's a typestate, so .panel exists only after it.
    • .panel(|b, value| ..): terminal. It builds exactly the selected panel.
  • Roles:
  • Keyboard:
    • The list is a Nav::Row(Wrap::Around) group (Roving arrow keys for groups on the page; radio_group on them (#346, PR 1) #368). It is one Tab stop, on the selected tab, or on the first enabled tab when the selected one is disabled.
    • ←/→ wrap, and Home/End go to the ends. ↑/↓ do nothing.
    • Disabled tabs are skipped.
    • Tab goes on into the panel's first focusable. The panel isn't a Tab stop (Q3 of the note).
  • Lazy panels with kept state. Each panel is keyed by its tab, so a panel that comes back finds what egui and eggshell keep per id, such as its scroll offset.
  • TabsStyle { gap }: the 8 pt between the list and the panel. It's installed like the other extras' styles (TabsStyle::of, install_for).

The look: the segmented control's, as decided

The list and the tabs draw through Style::segmented_track, segmented_cell and segmented_icon. A tab without an icon is a span, as a segmented cell is, so the nodes match one for one. A test checks every node's rect against segmented's, and the fills too.

Each value, under the shadcn preset with style-vega, against shadcn's tabs.tsx (apps/v4/registry/bases/radix/ui/tabs.tsx) and style-vega.css (.cn-tabs*):

What eggshell (preset, vega) shadcn Same?
list and panel gap TabsStyle::gap 8 .cn-tabs { gap-2 }, in every style-*.css ✓
list height control_height 36 .cn-tabs-list group-data-horizontal/tabs:h-9 ✓
list padding list_padding 3 .cn-tabs-list p-[3px] ✓
list radius radius 10 .cn-tabs-list rounded-lg ✓
list width w_fit tabs.tsx list w-fit ✓
list fill input tabs.tsx default: bg-muted ✗
tab radius radius_md() 8 .cn-tabs-trigger rounded-md ✓
tab padding cell_padding 8 × 4 .cn-tabs-trigger px-2 py-1 ✓
tab border 1, transparent at rest .cn-tabs-trigger border border-transparent ✓
tab text 14, medium .cn-tabs-trigger text-sm font-medium ✓
icon and label gap 6 .cn-tabs-trigger gap-1.5 ✓
icon size icon_size 16 .cn-tabs-trigger [&_svg:not([class*='size-'])]:size-4 ✓
tab width grow() tabs.tsx trigger flex-1 ✓
tab height the list's full height tabs.tsx trigger h-[calc(100%-1px)] ✗ (1 pt)
active, light background fill, foreground text data-active:bg-background data-active:text-foreground ✓
active, dark input/30 fill, input border, foreground text dark:data-active:bg-input/30 dark:data-active:border-input dark:data-active:text-foreground ✓
active shadow shadow_sm .cn-tabs-trigger data-active:shadow-sm (default variant) ✓
inactive text, light muted_foreground tabs.tsx trigger text-foreground/60 ✗
inactive text, dark muted_foreground dark:text-muted-foreground ✓
hover text unchanged hover:text-foreground (dark:hover:text-foreground) ✗
focus ring the style's focus ring, 3 at ring/50 focus-visible:ring-[3px] focus-visible:ring-ring/50 ✓
disabled the style's disabled look disabled:opacity-50 ✓ (preset's disabled)
panel text the inherited base role, 14 in vega .cn-tabs-content { text-sm } (text-xs/relaxed in lyra, which is each style's base) ✓
panel flex_1 tabs.tsx content flex-1 outline-none ✓

The four ✗ are the segmented look's, kept as decided, for you to check:

  • the list fill is input, not muted;
  • a tab is the list's full height, not 1 pt shorter;
  • an inactive tab's light-theme text is muted_foreground, not foreground/60;
  • there is no hover text change.

Changing them would change segmented too, or need a TabsStyle of its own. That's PR 4's render round, if you want it.

Tests

New in tests/it/tabs.rs, through kittest's real keys and pointer:

  • roles::the_list_is_a_named_tablist_of_tabs_the_current_one_selected
  • roles::the_panel_is_named_by_its_tab_and_the_tab_controls_it: only the selected tab names a panel.
  • pointer::a_click_selects_the_tab_and_its_panel_replaces_the_last
  • pointer::disabled_tabs_take_no_click: the whole control disabled.
  • pointer::a_disabled_tab_does_not_select
  • keyboard::the_list_is_one_tab_stop_on_the_selected_tab_and_tab_goes_on_into_the_panel
  • keyboard::the_arrows_select_as_they_move_and_wrap: one change per key.
  • keyboard::home_and_end_go_to_the_ends
  • keyboard::the_arrows_pass_over_a_disabled_tab
  • keyboard::up_and_down_do_nothing
  • keyboard::activated_on_enter_the_arrows_only_move_and_enter_selects
  • panels::only_the_selected_panel_is_built
  • panels::a_panel_keeps_its_scroll_across_a_switch_away_and_back
  • panels::when_the_selected_tab_is_disabled_the_first_enabled_tab_is_the_stop
  • look::the_tab_list_draws_as_the_segmented_control_does: every node's rect, the list's fill and each tab's fill.

Reversion check: on main the suite doesn't compile, because the feature is new. Each mutation below fails tests, and the unmutated branch passes all 15:

  • activation never follows focus: 4 fail;
  • the list stops at its ends: 1 fails;
  • no tab marked selected: 7 fail;
  • every tab controls the panel: 1 fails;
  • one panel key for every tab: 4 fail;
  • the relation names another panel id: 1 fails;
  • the panel named by the first tab: 1 fails;
  • the tabs ignore the control's enablement: 1 fails (a test added for it);
  • a tab drawn as a div with a text child: 1 fails;
  • the list left unnamed: 1 fails.

One first-draft line made no difference and is gone: a disabled tab's own inert(). The segmented cell classes are already inert when disabled (Paint::classes).

Checks

  • clippy (workspace, all targets, all features) and fmt are clean.
  • cargo test -p eggshell-ui passes (lib 334, it 1786), as do the extras' tests.
  • Main is merged in.
  • Doctests on the module and on TabsStyle.
  • No golden changed.

Breaking changes

None. A new feature.

TODO(prose)

The module doc, TabsExt::tabs, every TabsChain method, Unset, Changes and TabsStyle have one-line drafts for you to rewrite.

For you to try: this is a UI widget, so it gets a trial. That's PR 4, the gallery example, through the eggshell session. This PR has no example yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o

samitbasu and others added 3 commits November 19, 2026 15:28
…346, PR 3)

`b.tabs(key, current, options).on_change(..).panel(|b, value| ..)`, behind
a new `tabs` feature: a tab list that the arrows move through, and the
panel of the selected tab, built lazily.

- The list is a TabList group (`Nav::Row(Wrap::Around)`), one Tab stop on
  the selected tab; each tab a Tab item marked `selected`, the selected
  one `controls` its panel; the panel a TabPanel named by its tab.
- Activation follows focus by default (`selection_follows_focus`);
  `.activate_on_enter()` leaves the arrows to move focus only.
- The list and tabs draw in the segmented look, through
  `Style::segmented_track` / `segmented_cell` / `segmented_icon`; a tab
  without an icon is a span, as a segmented cell is.
- Each panel is keyed by its tab, so a panel coming back finds its state.
- `TabsStyle { gap }`: 8 pt between list and panel (shadcn's `gap-2`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
A disabled cell's classes are already inert (Paint::classes), so the
tab's own inert changed nothing; a test now disables the whole control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
# Conflicts:
#	Cargo.toml
#	crates/eggshell-ui-extras/Cargo.toml
# Conflicts:
#	Cargo.toml
#	crates/eggshell-ui-extras/Cargo.toml
# Conflicts:
#	Cargo.toml
#	crates/eggshell-ui-extras/Cargo.toml
@samitbasu

Copy link
Copy Markdown
Owner Author

Approved by the user after the Tabs trial (2026-11-19). GitHub's required checks pass on the branch merged with current main. Merging.

@samitbasu
samitbasu merged commit b6f765e into main Nov 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant