Skip to content

Commit dc443ee

Browse files
committed
fix: properly apply column maxWidth
1 parent 8910983 commit dc443ee

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export const normalizeOptions = (
281281
return {
282282
name: descriptor.name,
283283
align: descriptor.align ?? normalizedOptions.align,
284+
maxWidth: descriptor.maxWidth ?? normalizedOptions.maxWidth,
284285
overflowStrategy:
285286
descriptor.overflowStrategy ?? normalizedOptions.overflowStrategy,
286287
overflowHeaderStrategy:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| Name | Age | Is Cool? |
2+
| :---- | :-- | :------- |
3+
| Benja | 21 | false |
4+
min
5+
| Sarah | 22 | true |
6+
| Lee | 23 | true |

tests/basic-usage.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ describe("basic usage", () => {
129129
})
130130
).toMatchFileSnapshot(snapshotFile("wrap-maxWidth-5"));
131131
});
132+
test("wraps text to the given column-level `maxWidth`", async () => {
133+
const data = [
134+
{ name: "Benjamin", age: 21, isCool: false },
135+
{ name: "Sarah", age: 22, isCool: true },
136+
{ name: "Lee", age: 23, isCool: true }
137+
];
138+
139+
await expect(
140+
tablemark(data, {
141+
overflowStrategy: "wrap",
142+
maxWidth: 20,
143+
columns: [
144+
{ name: "Name", maxWidth: 5 },
145+
{ name: "Age" },
146+
{ name: "Is Cool?" }
147+
]
148+
})
149+
).toMatchFileSnapshot(snapshotFile("wrap-column-maxWidth-5"));
150+
});
132151

133152
test("wrap: handles newlines in a cell by adding rows as needed when `overflowStrategy: 'wrap'`", async () => {
134153
const data = [

0 commit comments

Comments
 (0)