Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/popular-cougars-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Vertically align cell contents in `DataTable`
11 changes: 5 additions & 6 deletions src/DataTable/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`
.TableHeader,
.TableCell {
text-align: start;
display: flex;
align-items: center;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about how this might affect the readability of rows where some cells have 1 line of text, and other cells wrap to 2+ lines.

Compare these two tables:
vertically centered rows

flush top rows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point. I'm not sure if the best solution is something that involves proper padding if there's a row action available, or increasing the base height of a row when there is no action. I don't think anyone but us is using DataTable at the moment, and our current plan is to truncate row content when it overflows a cell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late on this but I think align-items: baseline would solve for that specific issue, though not sure if it would introduce problems with other elements like IconButtons or Labels.

border-bottom: 1px solid ${get('colors.border.default')};
padding: var(--table-cell-padding);
}

.TableHeader[data-cell-align='end'],
Expand Down Expand Up @@ -102,12 +105,6 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`
border-bottom-right-radius: var(--table-border-radius);
}

/* TableHeader, TableCell */
.TableCell,
.TableHeader {
padding: var(--table-cell-padding);
}

/**
* Offset padding to make sure type aligns regardless of cell padding
* selection
Expand Down Expand Up @@ -160,6 +157,8 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`

/* TableCell */
.TableCell[scope='row'] {
align-items: center;
display: flex;
color: ${get('colors.fg.default')};
font-weight: 600;
}
Expand Down
18 changes: 18 additions & 0 deletions src/DataTable/__tests__/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ describe('Table', () => {
)
expect(screen.getByRole('rowheader', {name: 'Cell'})).toBeInTheDocument()
})

it('should vertically align cell contents', () => {
render(
<Table>
<Table.Head>
<Table.Row>
<Table.Header>Column</Table.Header>
</Table.Row>
</Table.Head>
<Table.Body>
<Table.Row>
<Table.Cell>Cell</Table.Cell>
</Table.Row>
</Table.Body>
</Table>,
)
expect(screen.getByRole('cell')).toHaveStyle('align-items: center')
})
})

describe('Table.Skeleton', () => {
Expand Down