Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/narrow-crumbs-settle.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions docs-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@
"symbols": ["DefaultHeader", "DefaultHeaderProps"],
"hashes": {
"typeSurface": "dfc505929b8ef505",
"outline": "efdd10f3fe946e62",
"outline": "bfe0749a841cef02",
"snapshot": null,
"outputMd": "375e55f4b12fa2be",
"outputMd": "e12bad2199a487d4",
"examples": null
}
},
Expand Down Expand Up @@ -841,9 +841,9 @@
"symbols": ["GlobalHeaderLayout", "GlobalHeaderLayoutProps"],
"hashes": {
"typeSurface": "70edbc7c68dcc7aa",
"outline": "44d1374ea9192b2e",
"outline": "caa5e1dd7e5ded0b",
"snapshot": null,
"outputMd": "fe86450720c4d586",
"outputMd": "16fa26b5097b3b35",
"examples": null
}
},
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions docs-src/components/default-header.docs.outline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs-src/components/global-header-layout.docs.outline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions docs/components/default-header.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/components/global-header-layout.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
<ol
data-slot="breadcrumb-list"
className={cn(
"astw:text-muted-foreground astw:flex astw:flex-wrap astw:items-center astw:gap-1.5 astw:text-body-md astw:break-words astw:sm:gap-2.5",
// Never wraps: a trail that does not fit truncates its items (see
// `BreadcrumbLink` / `BreadcrumbPage`) instead of stacking rows.
"astw:text-muted-foreground astw:flex astw:flex-nowrap astw:items-center astw:gap-1.5 astw:text-body-md astw:sm:gap-2.5",
className,
)}
{...props}
Expand All @@ -26,7 +28,7 @@ function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
return (
<li
data-slot="breadcrumb-item"
className={cn("astw:inline-flex astw:items-center astw:gap-1.5", className)}
className={cn("astw:inline-flex astw:min-w-0 astw:items-center astw:gap-1.5", className)}
{...props}
/>
);
Expand All @@ -41,7 +43,13 @@ function BreadcrumbLink({
}: React.ComponentProps<typeof Link> & {
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",
Expand All @@ -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}
/>
);
Expand All @@ -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 ?? <ChevronRight />}
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/components/sidebar/dynamic-breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -37,7 +38,7 @@ export const DynamicBreadcrumb = () => {
return (
<Breadcrumb>
<BreadcrumbList>
<div className="astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground">
<div className="astw:inline-flex astw:min-w-0 astw:items-center astw:gap-3 astw:last:text-foreground">
<BreadcrumbItem>
<BreadcrumbLink to={`/${isSettings.params.prefix}/settings`}>
{t("settings")}
Expand All @@ -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 (
<Breadcrumb>
<BreadcrumbList>
{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 (
<div
className="astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground"
className={cn(
"astw:inline-flex astw:min-w-0 astw:items-center astw:gap-3 astw:last:text-foreground",
collapseAncestors && !isLast && "astw:max-md:hidden",
)}
key={index}
>
<BreadcrumbItem>
Expand All @@ -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.
<BreadcrumbPage ariaCurrent={index === segments.length - 1 ? "location" : false}>
{title}
</BreadcrumbPage>
<BreadcrumbPage ariaCurrent={isLast ? "location" : false}>{title}</BreadcrumbPage>
)}
</BreadcrumbItem>
{index < segments.length - 1 && <BreadcrumbSeparator />}
{!isLast && <BreadcrumbSeparator />}
</div>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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: <Home /> },
component: () => <div>Dashboard</div>,
resources: [defineResource({ path: "orders", component: () => <div>Orders</div> })],
}),
];
window.history.pushState({}, "", "/dashboard/orders/ord-1");
render(
<AppShell title="My App" modules={modules}>
<GlobalHeaderLayout />
</AppShell>,
);

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: <Home /> },
component: () => <div>Dashboard</div>,
resources: [defineResource({ path: "orders", component: () => <div>Orders</div> })],
}),
];
window.history.pushState({}, "", "/dashboard/orders");
render(
<AppShell title="My App" modules={modules}>
<GlobalHeaderLayout />
</AppShell>,
);

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 });
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/components/sidebar/global-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ export const GlobalHeader = ({ actions }: GlobalHeaderProps) => {
<header className="astw:flex astw:h-14 astw:shrink-0 astw:items-center astw:justify-between astw:gap-2 astw:border-b astw:border-border astw:px-4">
<div className="astw:flex astw:min-w-0 astw:flex-1 astw:items-center astw:gap-2">
{icon}
<Text.span variant="heading-sm" className="astw:shrink-0 astw:truncate">
{/* 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. */}
<Text.span variant="heading-sm" className="astw:max-md:hidden astw:shrink-0 astw:truncate">
{title}
</Text.span>
<div className="astw:mx-1 astw:h-5 astw:w-px astw:shrink-0 astw:bg-border" />
<div className="astw:max-md:hidden astw:mx-1 astw:h-5 astw:w-px astw:shrink-0 astw:bg-border" />
<div className="astw:flex astw:min-w-0 astw:flex-1 astw:items-center astw:overflow-hidden">
<DynamicBreadcrumb />
</div>
Expand Down
Loading