Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/narrow-table-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tailor-platform/app-shell": patch
---

Keep the `DataTable` footer usable at phone widths. `DataTable.Pagination` now wraps its controls onto more lines instead of letting the frame clip them, so **Next** and **Last** stay tappable. When the footer is narrower than 480px, the **Rows per page** label is hidden and the page text is shortened to `1 / 5` (both stay available to screen readers, and the label now names the page-size select). The bulk-action bar also moves every action into the **More actions** menu at that width, so it keeps to one line and the table rows stay visible. The menu button gets an outline at that width, so it stands out more than **Clear**.
6 changes: 3 additions & 3 deletions docs-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@
],
"hashes": {
"typeSurface": "413c66caec0a0bf8",
"outline": "7591217822d0183b",
"outline": "a4288a1435b46ed4",
"snapshot": "a97e067c66e46ef6",
"outputMd": "36bb587b7088fb1c",
"outputMd": "c32c7ccf13528bf1",
"examples": "8adc119ac0d7152c"
}
},
Expand Down Expand Up @@ -1840,7 +1840,7 @@
"packages/core/skills/app-shell-patterns/references/components/combobox.md": "c79cd0fe175187e3",
"packages/core/skills/app-shell-patterns/references/components/command-palette.md": "7e5bc675a593791a",
"packages/core/skills/app-shell-patterns/references/components/csv-importer.md": "10c04c78bb846c9a",
"packages/core/skills/app-shell-patterns/references/components/data-table.md": "36bb587b7088fb1c",
"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-sidebar.md": "9b1672c71b6db3ff",
Expand Down
4 changes: 3 additions & 1 deletion docs-src/components/data-table.docs.outline.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ Add a name, minimum-quantity, or status filter, then edit or remove its chip. Th

Row selection is enabled by providing `rowSelection` or `onSelectionChange` to `useDataTable`. The `total` value comes from `DataTableData.total`. While the footer shows the bulk-action bar (see [Selection actions](#selection-actions)), the bar owns the selection count and this text is omitted.

In a narrow footer (under 480px wide, such as on a phone), the controls wrap onto more lines instead of being clipped. The **Rows per page** label is hidden, and the page text is shortened to `1 / 5`. Both stay available to screen readers. This only works inside `DataTable.Footer`, because the footer's own width is measured, not the viewport's.

When pagination changes page or page size, `DataTable.Table` resets its own scroll container to the top automatically. That applies whether navigation comes from the built-in `DataTable.Pagination` or from custom controls using the same table context.

Try First, Previous, Next, Last, and the page-size selector. This example supplies a small local cursor-based data source, including backward requests; `DataTable` itself does not slice the rows.
Expand Down Expand Up @@ -718,7 +720,7 @@ Confirmation, eligibility checks, and execution remain consumer-owned. A real ap
- **Return the promise from `onClick`.** While it is pending, the bar disables every action and shows a spinner on the running one, so a slow request can't be fired twice. Neither success nor rejection changes selection; there is no `keepSelection` option. A rejection is logged as `[DataTable] Selection action "…" failed`; showing it to the user is up to your handler.
- **Confirm dialogs can hand a later request back with `run`.** An `onClick` that only opens a dialog returns nothing. Keep the `run` helper and call it from the dialog's confirm button — `await run(deleteVendors(ids))` — to track that request in the bar. This only tracks pending state; it does not clear selection. Clear is disabled while a request is pending, and pending state survives the bar closing and reopening. Use controlled `rowSelection` to remove only successful ids, or call the explicit `clearSelection` helper if clearing every page is intentional.
- **Selection spans pages.** The header checkbox adds or removes only the current page; **Clear** empties everything.
- **Three actions stay inline.** The fourth onward collapse into a **More actions** menu, in array order. Put the most frequent first; a destructive action placed last sits safely in the menu.
- **Three actions stay inline.** The fourth onward collapse into a **More actions** menu, in array order. Put the most frequent first; a destructive action placed last sits safely in the menu. When the footer is narrower than 480px (for example, on a phone), every action moves into the menu, so the bar keeps to one line and the table rows stay visible. The menu button then gets an outline, like the inline actions.
- **Confirm destructive actions.** `variant: "destructive"` only styles the action. Open a confirm dialog from `onClick` before deleting — see the [confirm pattern](../patterns/interaction-confirm.md).
- **The bar stays reachable.** In `<Layout fill>` the footer is already pinned. On a page that scrolls, the bar sticks to the bottom of the viewport while rows are selected and settles back into place at the end of the table. It sticks to the nearest scrolling container: inside a scrolling drawer or panel it rides that container instead, and inside a wrapper that clips its overflow (such as a card with `overflow: hidden`) it simply stays in the footer.
- **Share presentation with `rowActions`.** Both action types extend the non-generic [`DataTableAction`](#datatableaction) (`id`, `label`, `icon`, `variant`). Keep row predicates on `RowAction<TRow>` and bulk business rules in the consumer's ID-based handler.
Expand Down
4 changes: 3 additions & 1 deletion docs/components/data-table.md

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

5 changes: 4 additions & 1 deletion packages/core/src/components/data-table/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ function DataTableFooter({ children, className }: { children?: ReactNode; classN
data-slot="data-table-footer"
data-selecting={selecting ? "" : undefined}
className={cn(
"astw:flex astw:shrink-0 astw:items-center astw:border-t astw:border-border astw:px-4 astw:py-2",
// A named container so Pagination can compact itself by the footer's
// own width, not the viewport's. The selection bar measures the same
// width in JS (see NARROW_FOOTER_WIDTH in selection-bar.tsx).
"astw:@container/data-table-footer astw:flex astw:shrink-0 astw:items-center astw:border-t astw:border-border astw:px-4 astw:py-2",
offersBulkActions && "astw:transition-colors astw:motion-reduce:transition-none",
selecting && [
"astw:flex-wrap astw:gap-x-3 astw:gap-y-2",
Expand Down
24 changes: 23 additions & 1 deletion packages/core/src/components/data-table/pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ function TestPagination({
data,
control,
onSelectionChange,
pageSizeOptions,
}: {
data: DataTableData<TestRow>;
control: CollectionControl;
onSelectionChange?: (ids: string[]) => void;
pageSizeOptions?: number[];
}) {
const table = useDataTable<TestRow>({
columns: testColumns,
Expand All @@ -60,7 +62,7 @@ function TestPagination({
return (
<DataTable.Root value={table}>
<DataTable.Footer>
<DataTable.Pagination />
<DataTable.Pagination pageSizeOptions={pageSizeOptions} />
</DataTable.Footer>
</DataTable.Root>
);
Expand Down Expand Up @@ -109,6 +111,26 @@ describe("DataTable.Pagination", () => {
expect(screen.queryByLabelText("Last page")).toBeNull();
});

it("names the page-size select with the Rows per page label", () => {
render(
<TestPagination data={dataWithTotal} control={makeControl()} pageSizeOptions={[10, 20]} />,
{ wrapper },
);

expect(screen.getByRole("combobox", { name: "Rows per page" })).not.toBeNull();
});

it("hides the short page text from assistive tech", () => {
render(<TestPagination data={dataWithTotal} control={makeControl()} />, {
wrapper,
});

// A narrow footer shows "1 / 5" in place of "Page 1 / 5"; only the full
// text should be announced.
expect(screen.getByText("1 / 5").getAttribute("aria-hidden")).toBe("true");
expect(screen.getByText("Page 1 / 5").getAttribute("aria-hidden")).toBeNull();
});

it("still shows Previous/Next buttons when total is not provided", () => {
render(<TestPagination data={dataWithoutTotal} control={makeControl()} />, {
wrapper,
Expand Down
83 changes: 62 additions & 21 deletions packages/core/src/components/data-table/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useId } from "react";
import { ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/button";
Expand All @@ -6,6 +7,14 @@ import { useDataTableContext } from "./context";
import { useDataTableT } from "./i18n";
import { isSelectionBarOpen } from "./selection-bar";

/**
* Visually hides a label while the footer is narrower than
* `NARROW_FOOTER_WIDTH` (see `selection-bar.tsx`), keeping it for screen
* readers. Outside `DataTable.Footer` the container never matches, so the
* label stays visible.
*/
const NARROW_FOOTER_SR_ONLY = "astw:@max-[480px]/data-table-footer:sr-only";

export interface DataTablePaginationProps {
/**
* Available page-size options shown in a dropdown selector.
Expand Down Expand Up @@ -34,6 +43,7 @@ export function DataTablePagination({ pageSizeOptions }: DataTablePaginationProp
toggleRowSelection,
} = ctx;
const t = useDataTableT();
const pageSizeLabelId = useId();

const selectionEnabled = toggleRowSelection !== undefined;
const selectedCount = selectedIds.length;
Expand All @@ -57,35 +67,66 @@ export function DataTablePagination({ pageSizeOptions }: DataTablePaginationProp
return (
// Beside the bar, flex-1 instead of w-full lets both share one line and
// wraps the controls onto a line of their own only when they don't fit.
// The row count, the page-size switcher and the page buttons are siblings
// in one wrapping row, so a narrow footer (phone widths) breaks between
// them instead of letting the table frame clip the buttons. The count's
// mr-auto keeps it on the left; everything else packs to the right.
<div
className={cn(
"astw:flex astw:items-center astw:justify-between astw:gap-2",
"astw:flex astw:flex-wrap astw:items-center astw:justify-end astw:gap-2",
barOpen ? "astw:flex-1" : "astw:w-full",
)}
>
{rowInfoText && (
<div className="astw:text-body-md astw:text-muted-foreground">{rowInfoText}</div>
<div className="astw:mr-auto astw:text-body-md astw:text-muted-foreground astw:whitespace-nowrap">
{rowInfoText}
</div>
)}
<div className="astw:flex astw:items-center astw:justify-end astw:gap-2 astw:ml-auto">
{pageSizeOptions && pageSizeOptions.length > 0 && (
<div className="astw:flex astw:items-center astw:gap-1.5">
<span className="astw:text-body-md astw:text-muted-foreground astw:whitespace-nowrap">
{t("paginationRowsPerPage")}
</span>
<Select
items={pageSizeOptions.map(String)}
value={String(pageSize)}
onValueChange={(item) => {
if (item) setPageSize(Number(item));
}}
className="astw:w-17.5"
/>
</div>
)}
{totalPages !== null && (
<span className="astw:text-body-md astw:text-muted-foreground astw:tabular-nums">
{t("paginationPage")} {currentPage} / {totalPages}
{pageSizeOptions && pageSizeOptions.length > 0 && (
<div className="astw:flex astw:items-center astw:gap-1.5">
{/* Names the select even while a narrow footer hides it visually. */}
<span
id={pageSizeLabelId}
className={cn(
"astw:text-body-md astw:text-muted-foreground astw:whitespace-nowrap",
NARROW_FOOTER_SR_ONLY,
)}
>
{t("paginationRowsPerPage")}
</span>
<Select
aria-labelledby={pageSizeLabelId}
items={pageSizeOptions.map(String)}
value={String(pageSize)}
onValueChange={(item) => {
if (item) setPageSize(Number(item));
}}
className="astw:w-17.5"
/>
</div>
)}
{/* The page text and its buttons wrap as one unit, so the buttons never
split across lines. */}
<div className="astw:flex astw:items-center astw:gap-2">
{totalPages !== null && (
<>
{/* The full "Page 1 / 5" stays one text node for screen readers
and text queries; a narrow footer shows "1 / 5" in its place. */}
<span
className={cn(
"astw:text-body-md astw:text-muted-foreground astw:tabular-nums astw:whitespace-nowrap",
NARROW_FOOTER_SR_ONLY,
)}
>
{t("paginationPage")} {currentPage} / {totalPages}
</span>
<span
aria-hidden="true"
className="astw:hidden astw:text-body-md astw:text-muted-foreground astw:tabular-nums astw:whitespace-nowrap astw:@max-[480px]/data-table-footer:inline"
>
{currentPage} / {totalPages}
</span>
</>
)}
<Button
variant="outline"
Expand Down
42 changes: 41 additions & 1 deletion packages/core/src/components/data-table/selection-bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,51 @@ describe("DataTable selection actions", () => {
wrapper,
});
expect(within(getBar()).queryByRole("button", { name: "Delete" })).toBeNull();
await user.click(within(getBar()).getByRole("button", { name: "More actions" }));
const menuTrigger = within(getBar()).getByRole("button", { name: "More actions" });
expect(menuTrigger.className).not.toContain("astw:border-border");
await user.click(menuTrigger);
await user.click(await screen.findByRole("menuitem", { name: "Delete" }));
expect(onDelete).toHaveBeenCalledExactlyOnceWith(["unseen", "3"], expect.any(Object));
});

it.each([
{ footerWidth: 360, inline: false },
{ footerWidth: 800, inline: true },
])(
"keeps actions inline only when the footer is wide enough (footer $footerWidth px)",
async ({ footerWidth, inline }) => {
// jsdom has no layout: stand in for the footer's measured width.
const clientWidth = vi
.spyOn(HTMLElement.prototype, "clientWidth", "get")
.mockReturnValue(footerWidth);
try {
const user = userEvent.setup();
const onArchive = vi.fn();
render(
<Harness rowSelection={{ actions: [archive(onArchive)], defaultSelectedIds: ["1"] }} />,
{
wrapper,
},
);
const inlineButton = within(getBar()).queryByRole("button", { name: "Archive" });
const menuTrigger = within(getBar()).queryByRole("button", { name: "More actions" });
if (inline) {
expect(inlineButton).not.toBeNull();
expect(menuTrigger).toBeNull();
return;
}
expect(inlineButton).toBeNull();
// The menu holds every action here, so it is outlined like them.
expect(menuTrigger!.className).toContain("astw:border-border");
await user.click(menuTrigger!);
await user.click(await screen.findByRole("menuitem", { name: "Archive" }));
expect(onArchive).toHaveBeenCalledExactlyOnceWith(["1"], expect.any(Object));
} finally {
clientWidth.mockRestore();
}
},
);

it("Clear empties selection and hands focus back to the header checkbox", async () => {
const user = userEvent.setup();
const onSelectionChange = vi.fn();
Expand Down
Loading
Loading