From 73ce85f96491c8e55bc16e9c6290351eb7a6ccdc Mon Sep 17 00:00:00 2001 From: Hiroki Uemura Date: Mon, 16 Nov 2026 09:54:02 +0900 Subject: [PATCH] fix(breadcrumb): keep the header trail on one line and readable on phones Below `md` the GlobalHeader hides the app title and its divider, and DynamicBreadcrumb shows only the current page when the trail is three or more segments deep. The breadcrumb list no longer wraps; a long page title truncates with an ellipsis, and each link is 24px tall (WCAG 2.5.8). Part of tailor-inc/platform-planning#2207 (Phase 2). --- .changeset/narrow-crumbs-settle.md | 6 ++ docs-manifest.json | 12 +-- .../components/default-header.docs.outline.md | 2 + .../global-header-layout.docs.outline.md | 2 + docs/components/default-header.md | 2 + docs/components/global-header-layout.md | 2 + .../internals/breadcrumb/breadcrumb.tsx | 21 ++++-- .../components/sidebar/dynamic-breadcrumb.tsx | 20 +++-- .../sidebar/global-header-layout.test.tsx | 75 ++++++++++++++++++- .../src/components/sidebar/global-header.tsx | 7 +- 10 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 .changeset/narrow-crumbs-settle.md diff --git a/.changeset/narrow-crumbs-settle.md b/.changeset/narrow-crumbs-settle.md new file mode 100644 index 000000000..043c11f96 --- /dev/null +++ b/.changeset/narrow-crumbs-settle.md @@ -0,0 +1,6 @@ +--- +"@tailor-platform/app-shell": patch +--- + +Keep the header breadcrumb readable on phones. Below the `md` breakpoint (768px) `GlobalHeaderLayout.DefaultHeader` hides the app title and its divider, and the route breadcrumb (both layouts) shows only the current page when the trail is three or more segments deep. +The breadcrumb no longer wraps onto extra lines: a long page title truncates with an ellipsis, and each link is 24px tall so it meets the WCAG 2.5.8 target size. diff --git a/docs-manifest.json b/docs-manifest.json index d8b0ebf23..d7218949c 100644 --- a/docs-manifest.json +++ b/docs-manifest.json @@ -518,9 +518,9 @@ "symbols": ["DefaultHeader", "DefaultHeaderProps"], "hashes": { "typeSurface": "dfc505929b8ef505", - "outline": "efdd10f3fe946e62", + "outline": "bfe0749a841cef02", "snapshot": null, - "outputMd": "375e55f4b12fa2be", + "outputMd": "e12bad2199a487d4", "examples": null } }, @@ -824,9 +824,9 @@ "symbols": ["GlobalHeaderLayout", "GlobalHeaderLayoutProps"], "hashes": { "typeSurface": "70edbc7c68dcc7aa", - "outline": "44d1374ea9192b2e", + "outline": "caa5e1dd7e5ded0b", "snapshot": null, - "outputMd": "fe86450720c4d586", + "outputMd": "16fa26b5097b3b35", "examples": null } }, @@ -1824,14 +1824,14 @@ "packages/core/skills/app-shell-patterns/references/components/csv-importer.md": "53d3c795ca21b9dc", "packages/core/skills/app-shell-patterns/references/components/data-table.md": "41de398263666fa7", "packages/core/skills/app-shell-patterns/references/components/date-picker.md": "d4b478c7ba8304d5", - "packages/core/skills/app-shell-patterns/references/components/default-header.md": "375e55f4b12fa2be", + "packages/core/skills/app-shell-patterns/references/components/default-header.md": "e12bad2199a487d4", "packages/core/skills/app-shell-patterns/references/components/default-sidebar.md": "9b1672c71b6db3ff", "packages/core/skills/app-shell-patterns/references/components/description-card.md": "a347fd1f4ccd433e", "packages/core/skills/app-shell-patterns/references/components/dialog.md": "e862d97903e8f596", "packages/core/skills/app-shell-patterns/references/components/document-progress-card.md": "d0fb940f685f8869", "packages/core/skills/app-shell-patterns/references/components/filter-rail.md": "224745760083ee35", "packages/core/skills/app-shell-patterns/references/components/form.md": "41bbf91bfb9f41d4", - "packages/core/skills/app-shell-patterns/references/components/global-header-layout.md": "fe86450720c4d586", + "packages/core/skills/app-shell-patterns/references/components/global-header-layout.md": "16fa26b5097b3b35", "packages/core/skills/app-shell-patterns/references/components/grid.md": "9051eb53dde4179f", "packages/core/skills/app-shell-patterns/references/components/input.md": "a3a6c9679af99d37", "packages/core/skills/app-shell-patterns/references/components/item-list.md": "0190e797cd8ed318", diff --git a/docs-src/components/default-header.docs.outline.md b/docs-src/components/default-header.docs.outline.md index c703acc89..f07ae77a8 100644 --- a/docs-src/components/default-header.docs.outline.md +++ b/docs-src/components/default-header.docs.outline.md @@ -13,6 +13,8 @@ sources: It is exposed as `SidebarLayout.DefaultHeader` (and as a top-level `DefaultHeader` export) so you can slightly extend the built-in header — the common case being adding a notification bell or user menu — without reconstructing the trigger and breadcrumb yourself. +The breadcrumb never wraps. Below the `md` breakpoint (768px) a trail of three or more segments shows only the current page, and a long page title truncates with an ellipsis. + ## Import ```tsx diff --git a/docs-src/components/global-header-layout.docs.outline.md b/docs-src/components/global-header-layout.docs.outline.md index 65d89c3fb..5028a5bcf 100644 --- a/docs-src/components/global-header-layout.docs.outline.md +++ b/docs-src/components/global-header-layout.docs.outline.md @@ -117,6 +117,8 @@ The layout's default header is also exported as a top-level `GlobalHeader` compo `actions` behaves the same way as on `SidebarLayout.DefaultHeader`: omitting it renders the built-in [`AppearanceSwitcher`](./appearance-switcher.md), and passing it replaces the entire right-hand cluster. +Below the `md` breakpoint (768px) the title and its divider are hidden, so the breadcrumb gets the whole left side. The breadcrumb itself never wraps: a trail of three or more segments shows only the current page at those widths, and a long page title truncates with an ellipsis instead of pushing the trail out of the header. + ```tsx import { AppearanceSwitcher, GlobalHeader } from "@tailor-platform/app-shell"; diff --git a/docs/components/default-header.md b/docs/components/default-header.md index 897337193..96af855ea 100644 --- a/docs/components/default-header.md +++ b/docs/components/default-header.md @@ -11,6 +11,8 @@ description: The built-in SidebarLayout top bar, extensible via an actions slot It is exposed as `SidebarLayout.DefaultHeader` (and as a top-level `DefaultHeader` export) so you can slightly extend the built-in header — the common case being adding a notification bell or user menu — without reconstructing the trigger and breadcrumb yourself. +The breadcrumb never wraps. Below the `md` breakpoint (768px) a trail of three or more segments shows only the current page, and a long page title truncates with an ellipsis. + ## Import ```tsx diff --git a/docs/components/global-header-layout.md b/docs/components/global-header-layout.md index d1a265bae..d592c4e0b 100644 --- a/docs/components/global-header-layout.md +++ b/docs/components/global-header-layout.md @@ -115,6 +115,8 @@ The layout's default header is also exported as a top-level `GlobalHeader` compo `actions` behaves the same way as on `SidebarLayout.DefaultHeader`: omitting it renders the built-in [`AppearanceSwitcher`](./appearance-switcher.md), and passing it replaces the entire right-hand cluster. +Below the `md` breakpoint (768px) the title and its divider are hidden, so the breadcrumb gets the whole left side. The breadcrumb itself never wraps: a trail of three or more segments shows only the current page at those widths, and a long page title truncates with an ellipsis instead of pushing the trail out of the header. + ```tsx import { AppearanceSwitcher, GlobalHeader } from "@tailor-platform/app-shell"; diff --git a/packages/core/src/components/internals/breadcrumb/breadcrumb.tsx b/packages/core/src/components/internals/breadcrumb/breadcrumb.tsx index 1de21aeaf..40dd54748 100644 --- a/packages/core/src/components/internals/breadcrumb/breadcrumb.tsx +++ b/packages/core/src/components/internals/breadcrumb/breadcrumb.tsx @@ -14,7 +14,9 @@ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
    ) { return (
  1. ); @@ -41,7 +43,13 @@ function BreadcrumbLink({ }: React.ComponentProps & { render?: React.ReactElement; }) { - const linkClassName = cn("astw:hover:text-foreground astw:transition-colors", className); + // `py-0.5` makes the link 24px tall (WCAG 2.5.8 target size) around the + // 20px line without changing the text; `min-w-0 truncate` lets a long title + // ellipsize instead of pushing the trail past the header. + const linkClassName = cn( + "astw:min-w-0 astw:truncate astw:py-0.5 astw:hover:text-foreground astw:transition-colors", + className, + ); return useRender({ defaultTagName: "a", @@ -67,7 +75,10 @@ function BreadcrumbPage({ data-slot="breadcrumb-page" aria-disabled="true" aria-current={ariaCurrent} - className={cn("astw:text-foreground astw:font-normal", className)} + className={cn( + "astw:min-w-0 astw:truncate astw:py-0.5 astw:text-foreground astw:font-normal", + className, + )} {...props} /> ); @@ -79,7 +90,7 @@ function BreadcrumbSeparator({ children, className, ...props }: React.ComponentP data-slot="breadcrumb-separator" role="presentation" aria-hidden="true" - className={cn("astw:[&>svg]:size-3.5", className)} + className={cn("astw:shrink-0 astw:[&>svg]:size-3.5", className)} {...props} > {children ?? } diff --git a/packages/core/src/components/sidebar/dynamic-breadcrumb.tsx b/packages/core/src/components/sidebar/dynamic-breadcrumb.tsx index b458e0395..c2fead3d4 100644 --- a/packages/core/src/components/sidebar/dynamic-breadcrumb.tsx +++ b/packages/core/src/components/sidebar/dynamic-breadcrumb.tsx @@ -11,6 +11,7 @@ import { import { processPathSegments } from "@/routing/path"; import { useBreadcrumbOverride } from "@/contexts/breadcrumb-context"; import { useT } from "@/i18n-labels"; +import { cn } from "@/lib/utils"; /** * Hook to retrieve the current path segments and their corresponding titles. @@ -37,7 +38,7 @@ export const DynamicBreadcrumb = () => { return ( -
    +
    {t("settings")} @@ -49,15 +50,24 @@ export const DynamicBreadcrumb = () => { ); } + // Below `md` a trail of three or more segments keeps only the last one (the + // current page); the ancestors are hidden with a responsive class, so the + // rule costs no JavaScript at runtime. + const collapseAncestors = segments.length >= 3; + return ( {segments.map((segmentInfo, index) => { const fullPath = basePath ? `/${basePath}/${segmentInfo.path}` : `/${segmentInfo.path}`; const title = overrides.get(fullPath) ?? segmentInfo.title; + const isLast = index === segments.length - 1; return (
    @@ -66,12 +76,10 @@ export const DynamicBreadcrumb = () => { ) : ( // Non-last segments use ariaCurrent={false} to avoid announcing // intermediate items as the current location to screen readers. - - {title} - + {title} )} - {index < segments.length - 1 && } + {!isLast && }
    ); })} diff --git a/packages/core/src/components/sidebar/global-header-layout.test.tsx b/packages/core/src/components/sidebar/global-header-layout.test.tsx index 6bb82bbd2..ec618af8b 100644 --- a/packages/core/src/components/sidebar/global-header-layout.test.tsx +++ b/packages/core/src/components/sidebar/global-header-layout.test.tsx @@ -6,7 +6,7 @@ import { ContentContainer } from "./content-container"; import { DynamicBreadcrumb } from "@/components/sidebar/dynamic-breadcrumb"; import { useAppShellSidebar } from "./use-app-shell-sidebar"; import { AppShell } from "@/components/appshell"; -import { defineModule } from "@/resource"; +import { defineModule, defineResource } from "@/resource"; import { Home } from "lucide-react"; afterEach(() => { @@ -58,6 +58,79 @@ describe("GlobalHeaderLayout", () => { }); }); + it("hides the app title below md and keeps only the current page in a deep breadcrumb", async () => { + stubDesktopViewport(); + const modules = [ + defineModule({ + path: "dashboard", + meta: { title: "Dashboard", icon: }, + component: () =>
    Dashboard
    , + resources: [defineResource({ path: "orders", component: () =>
    Orders
    })], + }), + ]; + window.history.pushState({}, "", "/dashboard/orders/ord-1"); + render( + + + , + ); + + const items = await waitFor(() => { + const found = document.querySelectorAll('[data-slot="breadcrumb-item"]'); + expect(found).toHaveLength(3); + return Array.from(found); + }); + + // The title is still rendered (desktop keeps it); only the responsive class hides it. + const header = document.querySelector("header")!; + const title = Array.from(header.querySelectorAll("span")).find( + (el) => el.textContent === "My App", + )!; + expect(title.className).toContain("astw:max-md:hidden"); + + // Three segments: the two ancestors carry the responsive class, the current page does not. + const wrappers = items.map((li) => li.parentElement!); + expect(wrappers.slice(0, 2).every((el) => el.className.includes("astw:max-md:hidden"))).toBe( + true, + ); + expect(wrappers[2].className).not.toContain("astw:max-md:hidden"); + + // The trail never wraps and each link is 24px tall for touch. + expect(document.querySelector('[data-slot="breadcrumb-list"]')!.className).toContain( + "astw:flex-nowrap", + ); + expect(document.querySelector('[data-slot="breadcrumb-link"]')!.className).toContain( + "astw:py-0.5", + ); + }); + + it("keeps every segment of a two-level breadcrumb at all widths", async () => { + stubDesktopViewport(); + const modules = [ + defineModule({ + path: "dashboard", + meta: { title: "Dashboard", icon: }, + component: () =>
    Dashboard
    , + resources: [defineResource({ path: "orders", component: () =>
    Orders
    })], + }), + ]; + window.history.pushState({}, "", "/dashboard/orders"); + render( + + + , + ); + + const items = await waitFor(() => { + const found = document.querySelectorAll('[data-slot="breadcrumb-item"]'); + expect(found).toHaveLength(2); + return Array.from(found); + }); + expect(items.some((li) => li.parentElement!.className.includes("astw:max-md:hidden"))).toBe( + false, + ); + }); + it("bakes hideHeader + iconRail into the default sidebar", async () => { stubDesktopViewport(); renderLayout({ defaultOpen: false }); diff --git a/packages/core/src/components/sidebar/global-header.tsx b/packages/core/src/components/sidebar/global-header.tsx index 7aac94b5a..df464ffc1 100644 --- a/packages/core/src/components/sidebar/global-header.tsx +++ b/packages/core/src/components/sidebar/global-header.tsx @@ -49,10 +49,13 @@ export const GlobalHeader = ({ actions }: GlobalHeaderProps) => {
    {icon} - + {/* Below `md` the breadcrumb (the current page) takes the whole left side: + the app title and its divider are hidden so the trail is not squeezed + to a few pixels at phone widths. */} + {title} -
    +