Skip to content

Commit a741242

Browse files
fix: made currentSortColumnId and currentSortDirection optional
1 parent f6bc143 commit a741242

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/DataTable/TableCol.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ type TableColProps<T> = {
9898
onDragEnd: (e: React.DragEvent<HTMLDivElement>) => void;
9999
onDragEnter: (e: React.DragEvent<HTMLDivElement>) => void;
100100
onDragLeave: (e: React.DragEvent<HTMLDivElement>) => void;
101-
currentSortColumnId: string | number | null;
102-
currentSortDirection: SortOrder;
101+
currentSortColumnId?: string | number | null;
102+
currentSortDirection?: SortOrder;
103103
};
104104

105105
function TableCol<T>({
@@ -172,14 +172,19 @@ function TableCol<T>({
172172
};
173173

174174
const renderNativeSortIcon = (sortActive: boolean) => (
175-
<NativeSortIcon sortActive={sortActive} sortDirection={currentSortDirection} />
175+
<NativeSortIcon sortActive={sortActive} sortDirection={currentSortDirection ?? sortDirection} />
176176
);
177177

178178
const renderCustomSortIcon = () => (
179179
<span className={[sortDirection, '__rdt_custom_sort_icon__'].join(' ')}>{sortIcon}</span>
180180
);
181181

182-
const sortActive = !!(column.sortable && currentSortColumnId !== null && equalizeId(currentSortColumnId, column.id));
182+
const sortActive = (() => {
183+
if (currentSortColumnId !== null) {
184+
return !!(column.sortable && equalizeId(currentSortColumnId, column.id));
185+
}
186+
return !!(column.sortable && equalizeId(selectedColumn.id, column.id));
187+
})();
183188
const disableSort = !column.sortable || disabled;
184189
const nativeSortIconLeft = column.sortable && !sortIcon && !column.right;
185190
const nativeSortIconRight = column.sortable && !sortIcon && column.right;

src/DataTable/defaultProps.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ExpanderCollapsedIcon from '../icons/ExpanderCollapsedIcon';
77
import ExpanderExpandedIcon from '../icons/ExpanderExpandedIcon';
88
import { noop } from './util';
99
import { Alignment, Direction } from './constants';
10-
import { SortOrder } from './types';
10+
// import { SortOrder } from './types';
1111

1212
export const defaultProps = {
1313
columns: [],
@@ -110,5 +110,5 @@ export const defaultProps = {
110110
keepExpandableFirst: false,
111111
footer: null,
112112
currentSortColumnId: null,
113-
currentSortDirection: 'asc' as SortOrder,
113+
currentSortDirection: undefined,
114114
};

src/DataTable/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export type TableProps<T> = {
118118
* */
119119
title?: string | React.ReactNode;
120120
footer?: React.ReactNode;
121-
currentSortColumnId: string | number | null;
122-
currentSortDirection: SortOrder;
121+
currentSortColumnId?: string | number | null;
122+
currentSortDirection?: SortOrder;
123123
};
124124

125125
export type TableColumnBase = {

0 commit comments

Comments
 (0)