Skip to content

Commit

Permalink
[TableSortLabel] Sort asc by default
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Dec 28, 2019
1 parent f3218f2 commit 0a2dfb4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api/table-sort-label.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A button based label for placing inside `TableCell` for column sorting.
| <span class="prop-name">active</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the label will have the active styling (should be true for the sorted column). |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | Label contents, the arrow will be appended automatically. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">direction</span> | <span class="prop-type">'asc'<br>&#124;&nbsp;'desc'</span> | <span class="prop-default">'desc'</span> | The current sort direction. |
| <span class="prop-name">direction</span> | <span class="prop-type">'asc'<br>&#124;&nbsp;'desc'</span> | <span class="prop-default">'asc'</span> | The current sort direction. |
| <span class="prop-name">hideSortIcon</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | Hide sort icon when active is false. |
| <span class="prop-name">IconComponent</span> | <span class="prop-type">elementType</span> | <span class="prop-default">ArrowDownwardIcon</span> | Sort icon to use. |

Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/components/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function EnhancedTableHead(props) {
>
<TableSortLabel
active={orderBy === headCell.id}
direction={order}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
Expand Down Expand Up @@ -221,8 +221,8 @@ export default function EnhancedTable() {
const [rowsPerPage, setRowsPerPage] = React.useState(5);

const handleRequestSort = (event, property) => {
const isDesc = orderBy === property && order === 'desc';
setOrder(isDesc ? 'asc' : 'desc');
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};

Expand Down
6 changes: 3 additions & 3 deletions docs/src/pages/components/tables/EnhancedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function EnhancedTableHead(props: EnhancedTableProps) {
>
<TableSortLabel
active={orderBy === headCell.id}
direction={order}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
Expand Down Expand Up @@ -249,8 +249,8 @@ export default function EnhancedTable() {
const [rowsPerPage, setRowsPerPage] = React.useState(5);

const handleRequestSort = (event: React.MouseEvent<unknown>, property: keyof Data) => {
const isDesc = orderBy === property && order === 'desc';
setOrder(isDesc ? 'asc' : 'desc');
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};

Expand Down
5 changes: 3 additions & 2 deletions packages/material-ui/src/TableSortLabel/TableSortLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const styles = theme => ({
'&:hover': {
color: theme.palette.text.secondary,
'& $icon': {
opacity: 1,
opacity: 0.5,
},
},
'&$active': {
Expand All @@ -36,6 +36,7 @@ export const styles = theme => ({
active: {},
/* Styles applied to the icon component. */
icon: {
fontSize: 18,
marginRight: 4,
marginLeft: 4,
opacity: 0,
Expand Down Expand Up @@ -63,7 +64,7 @@ const TableSortLabel = React.forwardRef(function TableSortLabel(props, ref) {
children,
classes,
className,
direction = 'desc',
direction = 'asc',
hideSortIcon = false,
IconComponent = ArrowDownwardIcon,
...other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ describe('<TableSortLabel />', () => {
assert.strictEqual(iconChildren.length, 1);
});

it('by default should have desc direction class', () => {
const wrapper = shallow(<TableSortLabel />);
const icon = wrapper.find(`.${classes.icon}`).first();
assert.strictEqual(icon.hasClass(classes.iconDirectionAsc), false);
assert.strictEqual(icon.hasClass(classes.iconDirectionDesc), true);
});

it('when given direction desc should have desc direction class', () => {
const wrapper = shallow(<TableSortLabel direction="desc" />);
const icon = wrapper.find(`.${classes.icon}`).first();
Expand Down
26 changes: 13 additions & 13 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"defaultSeverity": "error",
"extends": ["dtslint/dtslint.json"],
"jsRules": {},
"rules": {
"deprecation": true,
"file-name-casing": false,
"no-boolean-literal-compare": false,
"no-empty-interface": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-generics": false,
"no-redundant-jsdoc": false,
"semicolon": [true, "always", "ignore-bound-class-methods"]
}
"defaultSeverity": "error",
"extends": ["dtslint/dtslint.json"],
"jsRules": {},
"rules": {
"deprecation": true,
"file-name-casing": false,
"no-boolean-literal-compare": false,
"no-empty-interface": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-generics": false,
"no-redundant-jsdoc": false,
"semicolon": [true, "always", "ignore-bound-class-methods"]
}
}

0 comments on commit 0a2dfb4

Please sign in to comment.