@@ -25,10 +25,6 @@ import {
25
25
DATA_TABLE_COLUMN ,
26
26
} from '../../../utilities/constants' ;
27
27
28
- const defaultProps = {
29
- firstSortDirection : 'asc'
30
- } ;
31
-
32
28
/**
33
29
* Used internally, renders each individual column heading.
34
30
*/
@@ -84,8 +80,6 @@ class DataTableHeaderCell extends React.Component {
84
80
width : PropTypes . string ,
85
81
} ;
86
82
87
- static defaultProps = defaultProps ;
88
-
89
83
state = {
90
84
sortDirection : null ,
91
85
} ;
@@ -104,10 +98,16 @@ class DataTableHeaderCell extends React.Component {
104
98
handleSort = ( e ) => {
105
99
const oldSortDirection =
106
100
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 )
111
111
const data = {
112
112
property : this . props . property ,
113
113
sortDirection,
@@ -127,7 +127,7 @@ class DataTableHeaderCell extends React.Component {
127
127
const { fixedHeader, isSorted, label, sortable, width } = this . props ;
128
128
129
129
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
131
131
const expandedSortDirection =
132
132
sortDirection === 'desc' ? 'descending' : 'ascending' ;
133
133
const ariaSort = isSorted ? expandedSortDirection : 'none' ;
@@ -157,7 +157,7 @@ class DataTableHeaderCell extends React.Component {
157
157
name = { sortDirection === 'desc' ? 'arrowdown' : 'arrowup' }
158
158
size = "x-small"
159
159
/>
160
- { ( sortDirection && this . state . sortable ) ? (
160
+ { sortDirection ? (
161
161
< span
162
162
className = "slds-assistive-text"
163
163
aria-live = "assertive"
0 commit comments