Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BaseTable): aria-(multiselectable,selected) support added #33

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/BaseTable/BaseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import type {Row as RowType, Table as TableType} from '@tanstack/react-table';
import type {VirtualItem, Virtualizer} from '@tanstack/react-virtual';

import {getCellClassModes} from '../../utils';
import {getAriaMultiselectable, getCellClassModes} from '../../utils';
import {BaseDraggableRow} from '../BaseDraggableRow';
import {BaseFooterRow} from '../BaseFooterRow';
import type {BaseHeaderRowProps} from '../BaseHeaderRow';
Expand Down Expand Up @@ -162,6 +162,9 @@ export const BaseTable = React.forwardRef(
? (virtualItemOrRow as VirtualItem<HTMLTableRowElement>)
: undefined,
'aria-rowindex': headerRowCount + row.index + 1,
'aria-selected': table.options.enableRowSelection
? row.getIsSelected()
: undefined,
};

if (draggableContext) {
Expand All @@ -180,6 +183,7 @@ export const BaseTable = React.forwardRef(
data-dragging-row-index={draggingRowIndex > -1 ? draggingRowIndex : undefined}
aria-colcount={colCount > 0 ? colCount : undefined}
aria-rowcount={rowCount > 0 ? rowCount : undefined}
aria-multiselectable={getAriaMultiselectable(table)}
{...attributes}
>
{headerGroups && (
Expand Down
9 changes: 9 additions & 0 deletions src/utils/getAriaMultiselectable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {Table as TableType} from '@tanstack/table-core/build/lib/types';

export const getAriaMultiselectable = <TData>(table: TableType<TData>) => {
if (table.options.enableRowSelection) {
return Boolean(table.options.enableMultiRowSelection);
}

return undefined;
};
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 './getAriaMultiselectable';
export * from './getAriaSort';
export * from './getCellClassModes';
export * from './getCellStyles';
Expand Down
Loading