Skip to content

[fix] Allow empty section pages in top navigation similar to how we do it for sidebar nav #12247

Merged
sfc-gh-nbellante merged 26 commits intostreamlit:developfrom
nico-bellante:feature/top-nav-individual-pages
Sep 11, 2025
Merged

[fix] Allow empty section pages in top navigation similar to how we do it for sidebar nav #12247
sfc-gh-nbellante merged 26 commits intostreamlit:developfrom
nico-bellante:feature/top-nav-individual-pages

Conversation

@nico-bellante
Copy link
Copy Markdown
Contributor

@nico-bellante nico-bellante commented Aug 16, 2025

Summary

This PR fixes issue #12243 where pages with empty section headers ("") were incorrectly grouped in an unlabeled dropdown in the top navigation. They now appear as individual navigation items when mixed with sectioned pages, matching the behavior of sidebar navigation.

Changes

  • Added shared navigation utilities (processNavigationStructure) to ensure consistent handling of empty sections between TopNav and SidebarNav components
  • Refactored TopNav to use the shared utilities, fixing the bug where empty section pages were grouped incorrectly
  • Refactored SidebarNav to use the same shared utilities for consistency
  • Updated test IDs to properly distinguish between individual nav links and dropdown sections
  • Added comprehensive tests:
    • Unit tests for all navigation utilities
    • E2E test specifically for the mixed empty/named sections scenario

There's a couple suggestions @sfc-gh-dmatthews made that I think would be great here, but going to do in a follow up PR for easier review.

  1. Accept more than just "". Inspiration: https://docs.streamlit.io/develop/concepts/multipage-apps/overview#how-streamlit-converts-filenames-into-labels-and-titles We should allow various "empty" keys so that users can eventually place the single pages where they want (see idea 2)
  2. Once we can have multiple empty keys, we can allow the positioning of the single pages among sections should the developer choose to do so.

Another followup task could be to change what's getting screenshotted in the test app, or change the test app to use query params instead of checkboxes to avoid snap diffs on changing the options in the test app.

Testing

Added unit tests for utils and changed functionality. Added e2e tests. Manually verified.

Before/After

Before: Pages with empty section headers appeared in an unlabeled dropdown
After: Pages with empty section headers appear as individual navigation items

Example Usage

import streamlit as st

# These pages will appear as individual items in top nav
pages = {
    "": [
        st.Page("home.py", title="Home"),
        st.Page("dashboard.py", title="Dashboard"),
    ],
    "Admin": [
        st.Page("settings.py", title="Settings"),
        st.Page("users.py", title="Users"),
    ],
}

st.navigation(pages, position="top")

Fixes #12243

🤖 Generated with Claude Code

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Aug 16, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

This comment was marked as outdated.

@sfc-gh-nbellante sfc-gh-nbellante added security-assessment-completed change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Aug 19, 2025
@sfc-gh-nbellante sfc-gh-nbellante self-assigned this Aug 19, 2025
@sfc-gh-nbellante sfc-gh-nbellante force-pushed the feature/top-nav-individual-pages branch from f52e3ab to dfa5aa7 Compare August 20, 2025 19:44
@sfc-gh-nbellante sfc-gh-nbellante changed the title Fix empty section pages in top navigation (issue #12243) [fix] Allow empty section pages in top navigation similar to how we do it for sidebar nav Sep 3, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #12243 where pages with empty section headers ("") were incorrectly grouped in an unlabeled dropdown in the top navigation. The fix ensures that empty section pages appear as individual navigation items when mixed with sectioned pages, matching the behavior of sidebar navigation.

  • Added shared navigation utilities to ensure consistent handling of empty sections between TopNav and SidebarNav components
  • Refactored TopNav and SidebarNav to use the same shared processing logic
  • Updated test IDs to properly distinguish between different navigation contexts

Reviewed Changes

Copilot reviewed 10 out of 54 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/app/src/components/Navigation/utils.ts Added shared navigation processing utilities for consistent handling of empty sections
frontend/app/src/components/Navigation/utils.test.ts Added comprehensive unit tests for the new navigation utilities
frontend/app/src/components/Navigation/TopNav.tsx Refactored to use shared utilities and fix empty section handling
frontend/app/src/components/Navigation/TopNavSection.tsx Updated test IDs and added dropdown context parameter
frontend/app/src/components/Navigation/SidebarNavLink.tsx Enhanced test ID logic to distinguish dropdown links from regular nav links
frontend/app/src/components/Navigation/SidebarNav.tsx Refactored to use shared utilities and removed navSections prop
frontend/app/src/components/Navigation/SidebarNav.test.tsx Updated tests to work with refactored component interface
frontend/app/src/components/Sidebar/Sidebar.tsx Removed obsolete navSections prop from SidebarNav
e2e_playwright/multipage_apps_v2/mpa_v2_top_nav.py Added test case for mixed empty and named sections
e2e_playwright/multipage_apps_v2/mpa_v2_top_nav_test.py Added comprehensive E2E tests for mixed section navigation

@sfc-gh-nbellante sfc-gh-nbellante force-pushed the feature/top-nav-individual-pages branch from 2d85ef4 to 3bf71fc Compare September 4, 2025 16:58
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

at the root level.

and always on the top of the nav menu, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For now, yes. @sfc-gh-dmatthews had some thoughts about expanding on this further and allowing multiple different empty keys and allowing you to intermix so lets say the first section is "" and then next is "Section A" and then after section a is "_" or " " or "undefined" and then "Section B" allowing you to interweave the sections and pages. I think the sidebar design might need some work to make this look good, so I held off adding that in this PR.

Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 One clarification question

nico and others added 11 commits September 11, 2025 07:53
This file provides essential information for Claude Code instances working
with the Streamlit codebase, including common commands, architecture overview,
and development patterns.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Pages with empty section headers ("") now appear as individual items
in the top navigation bar when mixed with sectioned pages, matching
the behavior of sidebar navigation.

Changes:
- Add shared navigation utilities to process nav structure consistently
- Refactor TopNav to use shared utilities, fixing the unlabeled dropdown bug
- Refactor SidebarNav to use shared utilities for consistency
- Update test IDs to distinguish nav links from dropdown sections
- Add E2E test for mixed empty/named sections scenario
- Add comprehensive unit tests for navigation utilities

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@sfc-gh-nbellante sfc-gh-nbellante force-pushed the feature/top-nav-individual-pages branch from 9fe1142 to e9379cc Compare September 11, 2025 14:57
@sfc-gh-nbellante sfc-gh-nbellante merged commit 029b3e4 into streamlit:develop Sep 11, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show individual pages in the top nav bar outside of a section

4 participants