diff --git a/.changeset/popular-wasps-bathe.md b/.changeset/popular-wasps-bathe.md new file mode 100644 index 0000000..9b8ad65 --- /dev/null +++ b/.changeset/popular-wasps-bathe.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": minor +--- + +add width property to DataGrid columns diff --git a/packages/react/src/components/DataGrid/_index.scss b/packages/react/src/components/DataGrid/_index.scss index ab83e41..5668e97 100644 --- a/packages/react/src/components/DataGrid/_index.scss +++ b/packages/react/src/components/DataGrid/_index.scss @@ -23,6 +23,7 @@ border-collapse: collapse; font-weight: var(--c--theme--font--weights--regular); width: 100%; + table-layout: fixed; th, td { text-align: left; @@ -30,6 +31,7 @@ white-space: nowrap; font-size: var(--c--theme--font--sizes--m); height: 3rem; + overflow: hidden; } th { diff --git a/packages/react/src/components/DataGrid/index.spec.tsx b/packages/react/src/components/DataGrid/index.spec.tsx index 467915e..83378fd 100644 --- a/packages/react/src/components/DataGrid/index.spec.tsx +++ b/packages/react/src/components/DataGrid/index.spec.tsx @@ -381,4 +381,44 @@ describe("", () => { expect(tds[0].textContent).toEqual(row.sub.name); }); }); + + it("should render column with specific width", async () => { + const database = Array.from(Array(10)).map(() => ({ + id: faker.string.uuid(), + name: faker.person.fullName(), + email: faker.internet.email(), + })); + + const Component = () => { + return ( + + + + ); + }; + + render(); + + const table = screen.getByRole("table"); + const ths = getAllByRole(table, "columnheader"); + expect(ths.length).toBe(2); + expect(ths[0].textContent).toEqual("First name"); + expect(ths[1].textContent).toEqual("Email"); + + expect(ths[0].style.width).toEqual("50px"); + expect(ths[1].style.width).toEqual(""); + }); }); diff --git a/packages/react/src/components/DataGrid/index.stories.tsx b/packages/react/src/components/DataGrid/index.stories.tsx index c4a4bf2..a8a20ec 100644 --- a/packages/react/src/components/DataGrid/index.stories.tsx +++ b/packages/react/src/components/DataGrid/index.stories.tsx @@ -335,3 +335,57 @@ export const DataListOnly = () => { /> ); }; + +export const WithColumnWidth = () => { + const database = useMemo( + () => + Array.from(Array(23)).map(() => ({ + id: faker.string.uuid(), + firstName: faker.person.firstName(), + lastName: faker.person.lastName(), + email: faker.internet.email(), + address: faker.location.streetAddress(), + })), + [], + ); + return ( + ( +