Mantle Table Column Width Migration Guide
Table.Cell and Table.Header take a new width prop, and DataTable columns read the same value from meta.width. With no width, a cell now stays on one line. Each column shares the table's spare width, and a long value takes the width it needs. When the row is too narrow, the value truncates with an ellipsis, so every row keeps one height. width="fit" keeps a column on one line and never truncates it. It now also gets its share of the spare width. width="wrap" lets the text wrap, as every cell did before.
TL;DR: Pass width="wrap" to each cell and header whose text must wrap, such as prose or a multi-line note. Remove hand-set column widths such as w-[41%], w-full, or max-w-0, and remove truncate on a cell. The default does that now. Keep meta: { width: "fit" } on short columns.
Codemod
From a mantle checkout:
In a project that installs @ngrok/mantle:
The rule applies step 2. It adds width="wrap" to a Table.Cell, Table.Header, DataTable.Cell, or DataTable.Header whose className has a class that wraps text: whitespace-normal, whitespace-pre, whitespace-pre-wrap, whitespace-pre-line, whitespace-break-spaces, break-words, break-all, wrap-break-word, wrap-anywhere, or line-clamp-*. It also reads the strings inside a cx() call. It finds a part through its import from @ngrok/mantle/table or @ngrok/mantle/data-table, so a renamed import matches, and a part from another library or a local name that shadows the import stays. These stay manual:
- Step 3, because which column holds prose is a choice for each table.
- Steps 4 and 5, because a width or alignment class sits in a class string that can hold other classes.
- A class in a variable, or a string compared with
===,!==,==, or!=.
The codemod skips a part that already sets width, so it is safe to run twice. Pass --dry-run to print the rewrites first, and run your formatter after the rewrite.
You are an agent migrating a codebase. Do this:
- Find each
Table.Cell,Table.Header,DataTable.Cell, andDataTable.Headerfrom@ngrok/mantle/tableand@ngrok/mantle/data-table, with a renamed import too. - Add
width="wrap"to each one whoseclassNamehas a class from the## Codemodlist. In aDataTable, you can instead setmeta: { width: "wrap" }on the column and passcolumnto its header and to each cell. - Find a column that holds prose the reader must see in full, such as a message, a note, or an error, and give it
width="wrap"the same way. Leave a name, a description, a URL, an email, or an ID on the default: it truncates on one line. - Remove width classes from each cell and header: a fixed width such as
w-60, a percentage width such asw-1/3orw-[41%],w-full,w-0,max-w-*, andtruncateorwhitespace-nowrap. They do nothing now: a table with a header row is a CSS grid that sizes each column. Where a column needs a least width, putmin-w-*on its cells. - Replace a
vertical-alignclass on a cell or header with its grid form:align-topbecomescontent-start, andalign-bottombecomescontent-end. Cells center their content by default. - Find a short value of one shape, such as a date, a status, a count, or a duration. Give its column
width="fit"(meta: { width: "fit" }in aDataTable), so it never truncates and never holds a 6rem floor. - In tests: a default cell now wraps its children in a
<div data-slot="table-cell-content">, and each part sets its ARIA role.- A query by role and name stays the same:
getByRole("cell", { name: "web-10" }). - A check of the cell's direct children changes:
expect(cell.firstChild).toBe(link)becomesexpect(cell).toContainElement(link).
- A query by role and name stays the same:
- After editing, run the project's formatter, linter, type checker, and tests.
Why a grid that truncates by default? A table reads best when every column gets an equal share of the row and every row keeps one height. The browser's table layout gives the column with the longest values most of the spare width, and a hand-set percentage width leaves a gap after short values. A CSS grid with one
autotrack for each column splits the spare width equally, and the default cell can shrink to 6rem. The browser does this in its own layout pass. No script measures the table, so no work runs for each frame, and the server render does not shift on hydration.
Before → after
A cell with prose
A DataTable column with prose
A hand-set width
Edge cases & gotchas
- A default column has a floor of 6rem when the table is narrow. A short value in a default column holds that floor; give the column
width="fit". - A cell with an avatar and a name, or with badges, also stays on one line. Its content clips at the cell's edge. Add
truncateandmin-w-0to the text inside it to show an ellipsis. fitused to give its spare width to the other columns. Now each column gets an equal share. A column cannot be pinned to one width;min-w-*on its cells sets its least width.- A table with no
<thead>, with more than 24 columns, or with a spanning cell in its last header row keeps the table layout. There, the spare width is shared in proportion to content, as before. - In the grid, every cell in a row is as tall as the row, so a cell's border and background fill it.
- mantle's
Markdowntables passwidth="wrap", so their prose still wraps. - The
widthHTML attribute of<td>and<th>is obsolete; the prop replaces it.
How to verify
Then run the project's formatter, linter, type checker, and tests, and open each table at a wide and a narrow width. See step 6 for test changes.