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

fix: datatable.title numberOfLines > 1 height + wrapped text align #3015

Merged
merged 2 commits into from
Mar 30, 2022
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
23 changes: 22 additions & 1 deletion src/components/DataTable/DataTableTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ const DataTableTitle = ({
<Text
style={[
styles.cell,
// height must scale with numberOfLines
{ maxHeight: 24 * numberOfLines },
// if numberOfLines causes wrap, center is lost. Align directly, sensitive to numeric and RTL
numberOfLines > 1
? numeric
? I18nManager.isRTL
? styles.leftText
: styles.rightText
: styles.centerText
: {},
sortDirection ? styles.sorted : { color: textColor },
textStyle,
]}
Expand All @@ -150,12 +160,23 @@ const styles = StyleSheet.create({
paddingVertical: 12,
},

rightText: {
textAlign: 'right',
},

leftText: {
textAlign: 'left',
},

centerText: {
textAlign: 'center',
},

right: {
justifyContent: 'flex-end',
},

cell: {
height: 24,
lineHeight: 24,
fontSize: 12,
fontWeight: '500',
Expand Down
25 changes: 20 additions & 5 deletions src/components/__tests__/__snapshots__/DataTable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ exports[`renders data table header 1`] = `
"alignItems": "center",
"fontSize": 12,
"fontWeight": "500",
"height": 24,
"lineHeight": 24,
},
Object {
"maxHeight": 24,
},
Object {},
Object {
"color": "rgba(0, 0, 0, 0.6)",
},
Expand Down Expand Up @@ -158,9 +161,12 @@ exports[`renders data table header 1`] = `
"alignItems": "center",
"fontSize": 12,
"fontWeight": "500",
"height": 24,
"lineHeight": 24,
},
Object {
"maxHeight": 24,
},
Object {},
Object {
"color": "rgba(0, 0, 0, 0.6)",
},
Expand Down Expand Up @@ -1472,9 +1478,12 @@ exports[`renders data table title with press handler 1`] = `
"alignItems": "center",
"fontSize": 12,
"fontWeight": "500",
"height": 24,
"lineHeight": 24,
},
Object {
"maxHeight": 24,
},
Object {},
Object {
"marginLeft": 8,
},
Expand Down Expand Up @@ -1562,9 +1571,12 @@ exports[`renders data table title with sort icon 1`] = `
"alignItems": "center",
"fontSize": 12,
"fontWeight": "500",
"height": 24,
"lineHeight": 24,
},
Object {
"maxHeight": 24,
},
Object {},
Object {
"marginLeft": 8,
},
Expand Down Expand Up @@ -1670,9 +1682,12 @@ exports[`renders right aligned data table title 1`] = `
"alignItems": "center",
"fontSize": 12,
"fontWeight": "500",
"height": 24,
"lineHeight": 24,
},
Object {
"maxHeight": 24,
},
Object {},
Object {
"color": "rgba(0, 0, 0, 0.6)",
},
Expand Down