Skip to content

Commit

Permalink
[TableCell] Better handle long text (#8685)
Browse files Browse the repository at this point in the history
* removed whitespace from TabelCell root styles

* [Table] Better handle space
  • Loading branch information
lunzhang authored and oliviertassinari committed Oct 13, 2017
1 parent ce05ad1 commit e42339c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
9 changes: 6 additions & 3 deletions docs/src/pages/demos/tables/BasicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import Table, { TableBody, TableCell, TableHead, TableRow } from 'material-ui/Ta
import Paper from 'material-ui/Paper';

const styles = theme => ({
paper: {
root: {
width: '100%',
marginTop: theme.spacing.unit * 3,
overflowX: 'auto',
},
table: {
width: 700,
},
});

let id = 0;
Expand All @@ -32,8 +35,8 @@ function BasicTable(props) {
const { classes } = props;

return (
<Paper className={classes.paper}>
<Table>
<Paper className={classes.root}>
<Table className={classes.table}>
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
Expand Down
11 changes: 9 additions & 2 deletions docs/src/pages/demos/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class EnhancedTableHead extends React.Component {
numeric={column.numeric}
padding={column.disablePadding ? 'none' : 'default'}
>
<Tooltip title="Sort" placement="bottom-end" enterDelay={300}>
<Tooltip
title="Sort"
placement={column.numeric ? 'bottom-end' : 'bottom-start'}
enterDelay={300}
>
<TableSortLabel
active={orderBy === column.id}
direction={order}
Expand Down Expand Up @@ -163,6 +167,9 @@ const styles = theme => ({
width: '100%',
marginTop: theme.spacing.unit * 3,
},
table: {
width: 800,
},
tableWrapper: {
overflowX: 'auto',
},
Expand Down Expand Up @@ -264,7 +271,7 @@ class EnhancedTable extends React.Component {
<Paper className={classes.root}>
<EnhancedTableToolbar numSelected={selected.length} />
<div className={classes.tableWrapper}>
<Table>
<Table className={classes.table}>
<EnhancedTableHead
numSelected={selected.length}
order={order}
Expand Down
9 changes: 3 additions & 6 deletions src/Table/TableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ export type Props = {
export const styles = (theme: Object) => ({
root: {
borderBottom: `1px solid ${theme.palette.text.lightDivider}`,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
textAlign: 'left',
},
numeric: {
textAlign: 'right',
flexDirection: 'row-reverse', // can be dynamically inherited at runtime by contents
},
head: {
whiteSpace: 'pre',
fontWeight: theme.typography.fontWeightMedium,
position: 'relative', // Workaround for Tooltip positioning issue.
},
paddingDefault: {
padding: `0 ${theme.spacing.unit * 7}px 0 ${theme.spacing.unit * 3}px`,
padding: `${theme.spacing.unit / 2}px ${theme.spacing.unit * 7}px ${theme.spacing.unit /
2}px ${theme.spacing.unit * 3}px`,
'&:last-child': {
paddingRight: theme.spacing.unit * 3,
},
Expand All @@ -73,8 +71,7 @@ export const styles = (theme: Object) => ({
paddingRight: theme.spacing.unit * 3,
},
paddingCheckbox: {
paddingLeft: 12,
paddingRight: 12,
padding: '0 12px',
},
footer: {
borderBottom: 0,
Expand Down
32 changes: 15 additions & 17 deletions src/Table/TablePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const styles = (theme: Object) => ({
caption: {
flexShrink: 0,
},
selectRoot: {
marginRight: theme.spacing.unit * 4,
},
select: {
marginLeft: theme.spacing.unit,
width: 34,
Expand All @@ -41,9 +44,6 @@ export const styles = (theme: Object) => ({
height: 32,
lineHeight: '32px',
},
selectRoot: {
marginRight: theme.spacing.unit * 4,
},
actions: {
flexShrink: 0,
color: theme.palette.text.secondary,
Expand Down Expand Up @@ -178,20 +178,18 @@ class TablePagination extends React.Component<ProvidedProps & Props> {
<Typography type="caption" className={classes.caption}>
{labelRowsPerPage}
</Typography>
<Typography component="div" type="caption">
<Select
classes={{ root: classes.selectRoot, select: classes.select }}
input={<Input disableUnderline />}
value={rowsPerPage}
onChange={onChangeRowsPerPage}
>
{rowsPerPageOptions.map(rowsPerPageOption => (
<MenuItem key={rowsPerPageOption} value={rowsPerPageOption}>
{rowsPerPageOption}
</MenuItem>
))}
</Select>
</Typography>
<Select
classes={{ root: classes.selectRoot, select: classes.select }}
input={<Input disableUnderline />}
value={rowsPerPage}
onChange={onChangeRowsPerPage}
>
{rowsPerPageOptions.map(rowsPerPageOption => (
<MenuItem key={rowsPerPageOption} value={rowsPerPageOption}>
{rowsPerPageOption}
</MenuItem>
))}
</Select>
<Typography type="caption" className={classes.caption}>
{labelDisplayedRows({
from: count === 0 ? 0 : page * rowsPerPage + 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Table/TablePagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('<TablePagination />', () => {
assert.strictEqual(
wrapper
.find('withStyles(Typography)')
.at(2)
.at(1)
.text(),
'0-0 of 0',
);
Expand Down

0 comments on commit e42339c

Please sign in to comment.