Skip to content

Commit 03bdcad

Browse files
authored
Merge pull request #2 from sethu1504/minor-first-direction-update
First time sort direction logic update and testing
2 parents 15f3887 + 40c6b6a commit 03bdcad

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

components/data-table/private/header-cell.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import {
2525
DATA_TABLE_COLUMN,
2626
} from '../../../utilities/constants';
2727

28-
const defaultProps = {
29-
firstSortDirection: 'asc'
30-
};
31-
3228
/**
3329
* Used internally, renders each individual column heading.
3430
*/
@@ -84,8 +80,6 @@ class DataTableHeaderCell extends React.Component {
8480
width: PropTypes.string,
8581
};
8682

87-
static defaultProps = defaultProps;
88-
8983
state = {
9084
sortDirection: null,
9185
};
@@ -104,10 +98,16 @@ class DataTableHeaderCell extends React.Component {
10498
handleSort = (e) => {
10599
const oldSortDirection =
106100
this.props.sortDirection || this.state.sortDirection;
107-
var sortDirection = this.props.firstSortDirection
108-
if (oldSortDirection) {
109-
sortDirection = oldSortDirection === 'asc' ? 'desc' : 'asc'
110-
}
101+
const sortDirection = (function(sortDirection, firstDirection) {
102+
switch(sortDirection) {
103+
case 'asc':
104+
return 'desc'
105+
case 'desc':
106+
return 'asc'
107+
case null:
108+
return (firstDirection) ? firstDirection : 'asc'
109+
}
110+
})(oldSortDirection, this.props.firstSortDirection)
111111
const data = {
112112
property: this.props.property,
113113
sortDirection,
@@ -127,7 +127,7 @@ class DataTableHeaderCell extends React.Component {
127127
const { fixedHeader, isSorted, label, sortable, width } = this.props;
128128

129129
const labelType = typeof label;
130-
const sortDirection = (!this.props.sortDirection && !this.state.sortDirection) ? this.props.firstSortDirection : (this.props.sortDirection || this.state.sortDirection);
130+
const sortDirection = this.props.sortDirection || this.state.sortDirection || this.props.firstSortDirection
131131
const expandedSortDirection =
132132
sortDirection === 'desc' ? 'descending' : 'ascending';
133133
const ariaSort = isSorted ? expandedSortDirection : 'none';
@@ -157,7 +157,7 @@ class DataTableHeaderCell extends React.Component {
157157
name={sortDirection === 'desc' ? 'arrowdown' : 'arrowup'}
158158
size="x-small"
159159
/>
160-
{(sortDirection && this.state.sortable) ? (
160+
{sortDirection ? (
161161
<span
162162
className="slds-assistive-text"
163163
aria-live="assertive"

0 commit comments

Comments
 (0)