Skip to content

Commit

Permalink
Vertically align cell contents in DataTable (#3843)
Browse files Browse the repository at this point in the history
* Veritcally align cell contents

* Add test

* Change styles and add display: flex

* Fix test

* Create popular-cougars-look.md

---------

Co-authored-by: Josh Black <[email protected]>
  • Loading branch information
thyeggman and joshblack authored Oct 31, 2023
1 parent 82a4e30 commit 4ea8bcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
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;
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

0 comments on commit 4ea8bcf

Please sign in to comment.