diff --git a/packages/ibm-products/src/components/Datagrid/types/index.ts b/packages/ibm-products/src/components/Datagrid/types/index.ts index df6fd1e07a..8652a31bc1 100644 --- a/packages/ibm-products/src/components/Datagrid/types/index.ts +++ b/packages/ibm-products/src/components/Datagrid/types/index.ts @@ -264,6 +264,7 @@ export interface DataGridState onVirtualScroll?: (evt?: boolean) => void; fetchMoreData?: () => void; loadMoreThreshold?: number; + onSort?: boolean; } // DatagridHeaderRow related types diff --git a/packages/ibm-products/src/components/Datagrid/useSortableColumns.js b/packages/ibm-products/src/components/Datagrid/useSortableColumns.tsx similarity index 93% rename from packages/ibm-products/src/components/Datagrid/useSortableColumns.js rename to packages/ibm-products/src/components/Datagrid/useSortableColumns.tsx index 55cac510ca..d820ac80dd 100644 --- a/packages/ibm-products/src/components/Datagrid/useSortableColumns.js +++ b/packages/ibm-products/src/components/Datagrid/useSortableColumns.tsx @@ -12,6 +12,8 @@ import { Button } from '@carbon/react'; import { ArrowUp, ArrowDown, ArrowsVertical } from '@carbon/react/icons'; import { SelectAll } from './Datagrid/DatagridSelectAll'; import { DatagridSlug } from './Datagrid/addons/Slug/DatagridSlug'; +import { Hooks, TableInstance } from 'react-table'; +import { DataGridState } from './types'; const blockClass = `${pkg.prefix}--datagrid`; @@ -21,9 +23,9 @@ const ordering = { NONE: 'NONE', }; -export const getNewSortOrder = (sortOrder) => { +export const getNewSortOrder = (sortOrder?: boolean | string) => { const order = { - newSortDesc: undefined, + newSortDesc: false, newOrder: ordering.NONE, }; if (sortOrder === false || sortOrder === ordering.DESC) { @@ -71,7 +73,7 @@ const getAriaPressedValue = (col) => { return 'false'; }; -const useSortableColumns = (hooks) => { +const useSortableColumns = (hooks: Hooks) => { const sortableVisibleColumns = (visibleColumns, { instance }) => { const { onSort, @@ -171,8 +173,8 @@ const useSortableColumns = (hooks) => { : [...sortableColumns]; }; - const sortInstanceProps = (instance) => { - const { onSort } = instance; + const sortInstanceProps = (instance: TableInstance) => { + const { onSort } = instance as DataGridState; Object.assign(instance, { manualSortBy: !!onSort, isTableSortable: true }); };