Skip to content

Commit 4ea8bcf

Browse files
thyeggmanjoshblack
andauthored
Vertically align cell contents in DataTable (#3843)
* 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]>
1 parent 82a4e30 commit 4ea8bcf

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

.changeset/popular-cougars-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Vertically align cell contents in `DataTable`

src/DataTable/Table.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`
6666
.TableHeader,
6767
.TableCell {
6868
text-align: start;
69+
display: flex;
70+
align-items: center;
6971
border-bottom: 1px solid ${get('colors.border.default')};
72+
padding: var(--table-cell-padding);
7073
}
7174
7275
.TableHeader[data-cell-align='end'],
@@ -102,12 +105,6 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`
102105
border-bottom-right-radius: var(--table-border-radius);
103106
}
104107
105-
/* TableHeader, TableCell */
106-
.TableCell,
107-
.TableHeader {
108-
padding: var(--table-cell-padding);
109-
}
110-
111108
/**
112109
* Offset padding to make sure type aligns regardless of cell padding
113110
* selection
@@ -160,6 +157,8 @@ const StyledTable = styled.table<React.ComponentPropsWithoutRef<'table'>>`
160157
161158
/* TableCell */
162159
.TableCell[scope='row'] {
160+
align-items: center;
161+
display: flex;
163162
color: ${get('colors.fg.default')};
164163
font-weight: 600;
165164
}

src/DataTable/__tests__/Table.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ describe('Table', () => {
230230
)
231231
expect(screen.getByRole('rowheader', {name: 'Cell'})).toBeInTheDocument()
232232
})
233+
234+
it('should vertically align cell contents', () => {
235+
render(
236+
<Table>
237+
<Table.Head>
238+
<Table.Row>
239+
<Table.Header>Column</Table.Header>
240+
</Table.Row>
241+
</Table.Head>
242+
<Table.Body>
243+
<Table.Row>
244+
<Table.Cell>Cell</Table.Cell>
245+
</Table.Row>
246+
</Table.Body>
247+
</Table>,
248+
)
249+
expect(screen.getByRole('cell')).toHaveStyle('align-items: center')
250+
})
233251
})
234252

235253
describe('Table.Skeleton', () => {

0 commit comments

Comments
 (0)