Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table,datagrid): allow passing whiteSpace style prop #3740

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/shaggy-geese-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@twilio-paste/data-grid": minor
"@twilio-paste/table": minor
"@twilio-paste/core": minor
---

[Table, DataGrid] Allow passing `whiteSpace` style prop to `Th`/`DataGridHeader` and `Td`/`DataGridCell` components.
11 changes: 11 additions & 0 deletions packages/paste-core/components/data-grid/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ describe("Data Grid", () => {
expect(dataGrid.getAttribute("aria-label")).toBeDefined();
expect(dataGrid.getAttribute("role")).toBe("grid");
});

it("should render width, textAlign, and whiteSpace styles", (): void => {
render(<PlainDataGrid />);
const renderedTh = screen.getByTestId("data-grid-header");
const renderedTd = screen.getByTestId("data-grid-cell");
expect(renderedTh).toHaveStyleRule("text-align", "left");
expect(renderedTh).toHaveStyleRule("white-space", "normal");

expect(renderedTd).toHaveStyleRule("text-align", "left");
expect(renderedTd).toHaveStyleRule("white-space", "nowrap");
});
});

describe("Column Span", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/paste-core/components/data-grid/src/table/Td.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TdProps extends TableTdProps {
}

export const Td = React.forwardRef<HTMLTableCellElement, TdProps>(
({ textAlign = "left", element = "DATA_GRID_TD", ...props }, ref) => {
({ textAlign = "left", whiteSpace = "normal", element = "DATA_GRID_TD", ...props }, ref) => {
return (
<Box
{...safelySpreadBoxProps(props)}
Expand All @@ -23,6 +23,7 @@ export const Td = React.forwardRef<HTMLTableCellElement, TdProps>(
padding="space50"
position="relative"
textAlign={textAlign}
whiteSpace={whiteSpace}
verticalAlign="inherit"
wordWrap="break-word"
color="inherit"
Expand Down
3 changes: 2 additions & 1 deletion packages/paste-core/components/data-grid/src/table/Th.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ThProps extends TableThProps {
}

export const Th = React.forwardRef<HTMLTableCellElement, ThProps>(
({ width, textAlign = "left", element = "DATA_GRID_TH", ...props }, ref) => {
({ width, textAlign = "left", whiteSpace = "normal", element = "DATA_GRID_TH", ...props }, ref) => {
return (
<Box
{...safelySpreadBoxProps(props)}
Expand All @@ -25,6 +25,7 @@ export const Th = React.forwardRef<HTMLTableCellElement, ThProps>(
width={width}
position="relative"
textAlign={textAlign}
whiteSpace={whiteSpace}
verticalAlign="inherit"
color="inherit"
_first={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const PlainDataGrid: React.FC<React.PropsWithChildren<{ element?: BoxProp
key={`col-${colIndex}`}
data-testid={rowIndex === 0 && colIndex === 0 ? "data-grid-cell" : null}
textAlign={colIndex === 4 ? "right" : "left"}
whiteSpace="nowrap"
>
{col}
</DataGridCell>
Expand Down
14 changes: 14 additions & 0 deletions packages/paste-core/components/data-grid/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6504,6 +6504,13 @@
"required": false,
"externalProp": true
},
"whiteSpace": {
"type": "WhiteSpace",
"defaultValue": "'normal'",
"required": false,
"externalProp": false,
"description": "Sets how white space inside the Table cell is handled."
},
"width": {
"type": "Width<TLengthStyledSystem>",
"defaultValue": null,
Expand Down Expand Up @@ -11405,6 +11412,13 @@
"required": false,
"externalProp": true
},
"whiteSpace": {
"type": "WhiteSpace",
"defaultValue": "'normal'",
"required": false,
"externalProp": false,
"description": "Sets how white space inside the Table cell is handled."
},
"width": {
"type": "Width<TLengthStyledSystem>",
"defaultValue": null,
Expand Down
Loading