diff --git a/.changeset/narrow-table-footer.md b/.changeset/narrow-table-footer.md new file mode 100644 index 000000000..77e18bbdc --- /dev/null +++ b/.changeset/narrow-table-footer.md @@ -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**. diff --git a/docs-manifest.json b/docs-manifest.json index e61f12412..2c68be482 100644 --- a/docs-manifest.json +++ b/docs-manifest.json @@ -477,9 +477,9 @@ ], "hashes": { "typeSurface": "413c66caec0a0bf8", - "outline": "7591217822d0183b", + "outline": "a4288a1435b46ed4", "snapshot": "a97e067c66e46ef6", - "outputMd": "36bb587b7088fb1c", + "outputMd": "c32c7ccf13528bf1", "examples": "8adc119ac0d7152c" } }, @@ -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", diff --git a/docs-src/components/data-table.docs.outline.md b/docs-src/components/data-table.docs.outline.md index 2ccdfb808..9d6eafcc9 100644 --- a/docs-src/components/data-table.docs.outline.md +++ b/docs-src/components/data-table.docs.outline.md @@ -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. @@ -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 `` 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` and bulk business rules in the consumer's ID-based handler. diff --git a/docs/components/data-table.md b/docs/components/data-table.md index 54b7d0df7..d89a645a0 100644 --- a/docs/components/data-table.md +++ b/docs/components/data-table.md @@ -456,6 +456,8 @@ function Filtering() { 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. @@ -1882,7 +1884,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 `` 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` and bulk business rules in the consumer's ID-based handler. diff --git a/packages/core/src/components/data-table/footer.tsx b/packages/core/src/components/data-table/footer.tsx index 1445557f2..67bef90ba 100644 --- a/packages/core/src/components/data-table/footer.tsx +++ b/packages/core/src/components/data-table/footer.tsx @@ -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", diff --git a/packages/core/src/components/data-table/pagination.test.tsx b/packages/core/src/components/data-table/pagination.test.tsx index 7bb1a491c..1417ae03c 100644 --- a/packages/core/src/components/data-table/pagination.test.tsx +++ b/packages/core/src/components/data-table/pagination.test.tsx @@ -46,10 +46,12 @@ function TestPagination({ data, control, onSelectionChange, + pageSizeOptions, }: { data: DataTableData; control: CollectionControl; onSelectionChange?: (ids: string[]) => void; + pageSizeOptions?: number[]; }) { const table = useDataTable({ columns: testColumns, @@ -60,7 +62,7 @@ function TestPagination({ return ( - + ); @@ -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( + , + { wrapper }, + ); + + expect(screen.getByRole("combobox", { name: "Rows per page" })).not.toBeNull(); + }); + + it("hides the short page text from assistive tech", () => { + render(, { + 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(, { wrapper, diff --git a/packages/core/src/components/data-table/pagination.tsx b/packages/core/src/components/data-table/pagination.tsx index 8b2a5dd53..b59051b4c 100644 --- a/packages/core/src/components/data-table/pagination.tsx +++ b/packages/core/src/components/data-table/pagination.tsx @@ -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"; @@ -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. @@ -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; @@ -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.
{rowInfoText && ( -
{rowInfoText}
+
+ {rowInfoText} +
)} -
- {pageSizeOptions && pageSizeOptions.length > 0 && ( -
- - {t("paginationRowsPerPage")} - - { + if (item) setPageSize(Number(item)); + }} + className="astw:w-17.5" + /> +
+ )} + {/* The page text and its buttons wrap as one unit, so the buttons never + split across lines. */} +
+ {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. */} + + {t("paginationPage")} {currentPage} / {totalPages} + + + )}