Skip to content

Commit

Permalink
Merge branch 'main' into am-fix-act-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 authored Nov 22, 2024
2 parents e4eb8e7 + 041357f commit 373e7a3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@microsoft/api-extractor": "^7.23.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@tanstack/react-router": "^1.70.0",
"@tanstack/react-router": "1.82.1",
"@tanstack/router-plugin": "^1.69.1",
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^16.0.0",
Expand Down
8 changes: 6 additions & 2 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type SharedDivProps = Pick<
| 'role'
| 'aria-label'
| 'aria-labelledby'
| 'aria-description'
| 'aria-describedby'
| 'aria-rowcount'
| 'className'
Expand Down Expand Up @@ -260,6 +261,7 @@ function DataGrid<R, SR, K extends Key>(
role: rawRole,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
'aria-description': ariaDescription,
'aria-describedby': ariaDescribedBy,
'aria-rowcount': rawAriaRowCount,
'data-testid': testId
Expand Down Expand Up @@ -747,10 +749,10 @@ function DataGrid<R, SR, K extends Key>(
if (!isCellWithinSelectionBounds(position)) return;
commitEditorChanges();

const row = rows[position.rowIdx];
const samePosition = isSamePosition(selectedPosition, position);

if (enableEditor && isCellEditable(position)) {
const row = rows[position.rowIdx];
setSelectedPosition({ ...position, mode: 'EDIT', row, originalRow: row });
} else if (samePosition) {
// Avoid re-renders if the selected cell state is the same
Expand All @@ -765,7 +767,7 @@ function DataGrid<R, SR, K extends Key>(
if (onSelectedCellChange && !samePosition) {
onSelectedCellChange({
rowIdx: position.rowIdx,
row,
row: isRowIdxWithinViewportBounds(position.rowIdx) ? rows[position.rowIdx] : undefined,
column: columns[position.idx]
});
}
Expand Down Expand Up @@ -1081,10 +1083,12 @@ function DataGrid<R, SR, K extends Key>(
selectedPosition.idx === -1 && selectedPosition.rowIdx !== minRowIdx - 1;

return (
// biome-ignore lint/a11y/useValidAriaProps: aria-description is a valid prop
<div
role={role}
aria-label={ariaLabel}
aria-labelledby={ariaLabelledBy}
aria-description={ariaDescription}
aria-describedby={ariaDescribedBy}
aria-multiselectable={isSelectable ? true : undefined}
aria-colcount={columns.length}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export type CellKeyDownArgs<TRow, TSummaryRow = unknown> =

export interface CellSelectArgs<TRow, TSummaryRow = unknown> {
rowIdx: number;
row: TRow;
row: TRow | undefined;
column: CalculatedColumn<TRow, TSummaryRow>;
}

Expand Down
8 changes: 8 additions & 0 deletions test/browser/events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ describe('Events', () => {
rowIdx: 0
});
expect(onSelectedCellChange).toHaveBeenCalledTimes(5);

// go to the header row
await userEvent.keyboard('{ArrowUp}');
expect(onSelectedCellChange).toHaveBeenCalledWith({
column: expect.objectContaining(columns[1]),
row: undefined,
rowIdx: -1
});
});
});

Expand Down
18 changes: 18 additions & 0 deletions test/browser/label.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getGrid, setup } from './utils';

test('should set label and description', () => {
setup({
rows: [],
columns: [],
'aria-label': 'label',
'aria-labelledby': 'labelledby',
'aria-description': 'description',
'aria-describedby': 'describedby'
});

const grid = getGrid().element();
expect(grid).toHaveAttribute('aria-label', 'label');
expect(grid).toHaveAttribute('aria-labelledby', 'labelledby');
expect(grid).toHaveAttribute('aria-description', 'description');
expect(grid).toHaveAttribute('aria-describedby', 'describedby');
});

0 comments on commit 373e7a3

Please sign in to comment.