Skip to content

Commit

Permalink
feat(Table): aria-sort support added (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanisAvko authored Aug 14, 2024
1 parent 018dd18 commit 81987fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/HeaderCell/HeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import type {Header} from '@tanstack/react-table';
import {flexRender} from '@tanstack/react-table';

import {getCellStyles, getHeaderCellClassModes} from '../../utils';
import {getAriaSort, getCellStyles, getHeaderCellClassModes} from '../../utils';
import type {ResizeHandleProps} from '../ResizeHandle';
import {ResizeHandle} from '../ResizeHandle';
import type {SortIndicatorProps} from '../SortIndicator';
Expand Down Expand Up @@ -72,6 +72,7 @@ export const HeaderCell = <TData, TValue>({
rowSpan={rowSpan > 1 ? rowSpan : undefined}
onClick={header.column.getToggleSortingHandler()}
style={getCellStyles(header)}
aria-sort={getAriaSort(header.column.getIsSorted())}
{...attributes}
>
{flexRender(header.column.columnDef.header, header.getContext())}{' '}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/getAriaSort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {SortDirection} from '@tanstack/react-table';

export const getAriaSort = (sortDirection: SortDirection | false) => {
if (!sortDirection) {
return undefined;
}

return sortDirection === 'asc' ? 'ascending' : 'descending';
};
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './cn';
export * from './getAriaSort';
export * from './getCellClassModes';
export * from './getCellStyles';
export * from './getColumnPinningClassModes';
Expand Down

0 comments on commit 81987fe

Please sign in to comment.