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 2c68be482..49da584f8 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 } }, @@ -841,9 +841,9 @@ "symbols": ["GlobalHeaderLayout", "GlobalHeaderLayoutProps"], "hashes": { "typeSurface": "70edbc7c68dcc7aa", - "outline": "44d1374ea9192b2e", + "outline": "caa5e1dd7e5ded0b", "snapshot": null, - "outputMd": "fe86450720c4d586", + "outputMd": "16fa26b5097b3b35", "examples": null } }, @@ -1842,14 +1842,14 @@ "packages/core/skills/app-shell-patterns/references/components/csv-importer.md": "10c04c78bb846c9a", "packages/core/skills/app-shell-patterns/references/components/data-table.md": "c32c7ccf13528bf1", "packages/core/skills/app-shell-patterns/references/components/date-picker.md": "376e7d4ad14c2934", - "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": "8930a410d7d45f89", "packages/core/skills/app-shell-patterns/references/components/dialog.md": "cd9fa9c4b8ccb108", "packages/core/skills/app-shell-patterns/references/components/document-progress-card.md": "cabfb86627aefd6f", "packages/core/skills/app-shell-patterns/references/components/filter-rail.md": "12021e27b57f45e9", "packages/core/skills/app-shell-patterns/references/components/form.md": "c97c3d6e426d8b29", - "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": "d048e972ae8aba3e", "packages/core/skills/app-shell-patterns/references/components/input.md": "876dca4c3b3bc9c5", "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} -
    +