Skip to content

Commit

Permalink
fix: made currentSortColumnId and currentSortDirection optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ravgeetdhillon committed Jul 24, 2023
1 parent f6bc143 commit a741242
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/DataTable/TableCol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type TableColProps<T> = {
onDragEnd: (e: React.DragEvent<HTMLDivElement>) => void;
onDragEnter: (e: React.DragEvent<HTMLDivElement>) => void;
onDragLeave: (e: React.DragEvent<HTMLDivElement>) => void;
currentSortColumnId: string | number | null;
currentSortDirection: SortOrder;
currentSortColumnId?: string | number | null;
currentSortDirection?: SortOrder;
};

function TableCol<T>({
Expand Down Expand Up @@ -172,14 +172,19 @@ function TableCol<T>({
};

const renderNativeSortIcon = (sortActive: boolean) => (
<NativeSortIcon sortActive={sortActive} sortDirection={currentSortDirection} />
<NativeSortIcon sortActive={sortActive} sortDirection={currentSortDirection ?? sortDirection} />
);

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

const sortActive = !!(column.sortable && currentSortColumnId !== null && equalizeId(currentSortColumnId, column.id));
const sortActive = (() => {
if (currentSortColumnId !== null) {
return !!(column.sortable && equalizeId(currentSortColumnId, column.id));
}
return !!(column.sortable && equalizeId(selectedColumn.id, column.id));
})();
const disableSort = !column.sortable || disabled;
const nativeSortIconLeft = column.sortable && !sortIcon && !column.right;
const nativeSortIconRight = column.sortable && !sortIcon && column.right;
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable/defaultProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ExpanderCollapsedIcon from '../icons/ExpanderCollapsedIcon';
import ExpanderExpandedIcon from '../icons/ExpanderExpandedIcon';
import { noop } from './util';
import { Alignment, Direction } from './constants';
import { SortOrder } from './types';
// import { SortOrder } from './types';

export const defaultProps = {
columns: [],
Expand Down Expand Up @@ -110,5 +110,5 @@ export const defaultProps = {
keepExpandableFirst: false,
footer: null,
currentSortColumnId: null,
currentSortDirection: 'asc' as SortOrder,
currentSortDirection: undefined,
};
4 changes: 2 additions & 2 deletions src/DataTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export type TableProps<T> = {
* */
title?: string | React.ReactNode;
footer?: React.ReactNode;
currentSortColumnId: string | number | null;
currentSortDirection: SortOrder;
currentSortColumnId?: string | number | null;
currentSortDirection?: SortOrder;
};

export type TableColumnBase = {
Expand Down

0 comments on commit a741242

Please sign in to comment.