Skip to content

feat(Tabs): order tab panels independently of mount order - #334

Merged
Quis90 merged 2 commits into
masterfrom
tabs-panel-order
Sep 22, 2026
Merged

Quis90 merged 2 commits into
masterfrom
tabs-panel-order

Conversation

@Quis90

@Quis90 Quis90 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

TabsHeader rendered the tabs in the order they registered themselves. A panel that mounts later than its siblings therefore always ends up last, no matter where it sits in the children — e.g. a tab bar where a new panel is added next to an existing group at runtime.

This adds an optional order prop to TabPanel. TabsHeader sorts by it, and panels without an order keep the order they mounted in, so existing consumers see no change.

Alternative rejected: deriving the position from the children of Tabs. Panels register themselves through the context from arbitrary depth (wrapped in providers, spinners, form wrappers), so their JSX position is not available where the header renders.

The regression test uses explicit keys on purpose — without them React reconciles the panels positionally and they re-register in the right order by accident, which makes the test pass even without the sort.

🤖 Generated with Claude Code

TabsHeader listed the tabs in the order they registered themselves, so a
panel that mounted later always appeared last, no matter where it sat in
the children. The new optional order prop decides the position instead.

Panels without an order keep the order they mounted in, so existing
consumers are unaffected.

🤖 Generated with Claude Code
@Quis90 Quis90 self-assigned this Sep 15, 2026
@Quis90
Quis90 requested a review from spawnia September 15, 2026 13:22
@Quis90
Quis90 marked this pull request as ready for review September 15, 2026 13:22
@Quis90
Quis90 requested a lite review from Copilot September 15, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate issues affect active-tab selection and order updates.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds an optional order prop to TabPanel so tab headers can be ordered independently of mount order.

Changes:

  • Adds order to TabPanelProps.
  • Sorts tab headers by order.
  • Registers panel ordering metadata.
  • Adds regression coverage for dynamically mounted panels.
File summaries
File Summary
src/Tabs/types.ts Defines the optional order prop.
src/Tabs/TabsHeader.tsx Sorts headers, but active-tab selection can still follow registration order (moderate; 1 vote).
src/Tabs/TabPanel.tsx Registers ordering, but order changes can clear active selection and alter tie-breaking (moderate; 3 votes).
src/Tabs/index.test.tsx Tests ordering for dynamically mounted panels.
Review details

Suppressed comments (1)

src/Tabs/TabsHeader.tsx:50

  • Sorting only the header leaves Tabs.tsx's active-tab state in registration order. With panels mounted as 3(order 3), 1(order 1), and 2(order 2), the last visual tab is initially active; after removing the active panel 1, the reducer also falls back to the first registered remaining tab 3 instead of the first displayed tab 2. Apply the same ordering to initial/fallback selection (or keep ordered tabs in state) so selection follows the rendered order.
      {sortedByOrder(context.tabs).map((tab: TabPanelProps) => {
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Tabs/TabPanel.tsx Outdated
Registering an already known tab now updates it in place, so a title or
order change no longer unregisters and re-registers the panel.
Unregistering only reassigns the active tab when the removed one was
active, falling back to the first displayed tab instead of the first
registered one.

🤖 Generated with Claude Code
@Quis90
Quis90 requested review from mic-web and removed request for spawnia September 16, 2026 12:57
@Quis90
Quis90 merged commit f01d2fb into master Sep 22, 2026
7 checks passed
@Quis90
Quis90 deleted the tabs-panel-order branch September 22, 2026 07:23
github-actions Bot pushed a commit that referenced this pull request Sep 22, 2026
# [20.8.0](v20.7.1...v20.8.0) (2026-09-22)

### Features

* **Tabs:** order tab panels independently of mount order ([#334](#334)) ([f01d2fb](f01d2fb))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 20.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Development

Successfully merging this pull request may close these issues.

3 participants