📱 let the header action toolbar shrink on narrow viewports
Browse files at this commitffc324a80468d96bf5e10b5e745b7c2df586798fParent: 896684b- fix
- 📱 let the header action toolbar shrink on narrow viewports
3 changed files +30 -2
- src/components/ui/data-section.tsx +1 -1
- src/components/ui/data-table.test.tsx +28 -0
- src/components/ui/data-table.tsx +1 -1
src/components/ui/data-section.tsxmodified+1 -1
| @@ -22,7 +22,7 @@ export function DataSection( | |||
| 22 | </Show> | 22 | </Show> |
| 23 | </div> | 23 | </div> |
| 24 | <Show when={props.actions}> | 24 | <Show when={props.actions}> |
| 25 | - <div class="flex shrink-0 flex-wrap items-center gap-2 [&_button]:h-9 [&_button]:rounded-md">{props.actions}</div> | 25 | + <div class="flex min-w-0 flex-wrap items-center gap-2 [&_button]:h-9 [&_button]:rounded-md">{props.actions}</div> |
| 26 | </Show> | 26 | </Show> |
| 27 | </div> | 27 | </div> |
| 28 | </Show> | 28 | </Show> |
src/components/ui/data-table.test.tsxmodified+28 -0
| @@ -1,6 +1,7 @@ | |||
| 1 | import { fireEvent, render, screen } from "@solidjs/testing-library"; | 1 | import { fireEvent, render, screen } from "@solidjs/testing-library"; |
| 2 | import type { ColumnDef } from "@tanstack/solid-table"; | 2 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 3 | import { DataTable } from "@/components/ui/data-table"; | 3 | import { DataTable } from "@/components/ui/data-table"; |
| 4 | +import { DataSection } from "@/components/ui/data-section"; | ||
| 4 | import { PreferencesProvider } from "@/stores/preferences-context"; | 5 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 5 | 6 | ||
| 6 | type Row = { name: string; role?: string }; | 7 | type Row = { name: string; role?: string }; |
| @@ -119,3 +120,30 @@ test("a display column renders its own cell instead of the empty dash", () => { | |||
| 119 | 120 | ||
| 120 | expect(screen.getByText("#ada")).toBeTruthy(); | 121 | expect(screen.getByText("#ada")).toBeTruthy(); |
| 121 | }); | 122 | }); |
| 123 | + | ||
| 124 | +test("the header action toolbar of every shared host can shrink below its max-content width", () => { | ||
| 125 | + // `shrink-0` plus the flex default `min-width: auto` pinned the toolbar to | ||
| 126 | + // its max-content width, so a wide action row pushed the whole document | ||
| 127 | + // past a 390px viewport instead of wrapping inside the constrained parent. | ||
| 128 | + render(() => ( | ||
| 129 | + <> | ||
| 130 | + <PreferencesProvider> | ||
| 131 | + <DataTable | ||
| 132 | + columns={[columns[0]]} | ||
| 133 | + data={[{ name: "Ada" }]} | ||
| 134 | + enableColumnVisibility={false} | ||
| 135 | + actions={<button type="button">Export</button>} | ||
| 136 | + /> | ||
| 137 | + </PreferencesProvider> | ||
| 138 | + <DataSection title="Card" actions={<button type="button">Export</button>} /> | ||
| 139 | + </> | ||
| 140 | + )); | ||
| 141 | + | ||
| 142 | + const toolbars = screen.getAllByText("Export").map((action) => action.parentElement as HTMLElement); | ||
| 143 | + expect(toolbars).toHaveLength(2); | ||
| 144 | + for (const toolbar of toolbars) { | ||
| 145 | + expect(toolbar.classList).toContain("flex-wrap"); | ||
| 146 | + expect(toolbar.classList).toContain("min-w-0"); | ||
| 147 | + expect(toolbar.classList).not.toContain("shrink-0"); | ||
| 148 | + } | ||
| 149 | +}); | ||
src/components/ui/data-table.tsxmodified+1 -1
| @@ -264,7 +264,7 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | |||
| 264 | </Show> | 264 | </Show> |
| 265 | </div> | 265 | </div> |
| 266 | <Show when={props.actions}> | 266 | <Show when={props.actions}> |
| 267 | - <div class="flex shrink-0 flex-wrap items-center gap-2 [&_button]:h-9 [&_button]:rounded-md">{props.actions}</div> | 267 | + <div class="flex min-w-0 flex-wrap items-center gap-2 [&_button]:h-9 [&_button]:rounded-md">{props.actions}</div> |
| 268 | </Show> | 268 | </Show> |
| 269 | </div> | 269 | </div> |
| 270 | </Show> | 270 | </Show> |