Skip to content

Commit aec3d0f

Browse files
committed
Merge branch 'main' into clarity
1 parent 1f09988 commit aec3d0f

35 files changed

+693
-672
lines changed

README.md

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ An array of rows, the rows data can be of any type.
276276

277277
###### `ref?: Maybe<React.Ref<DataGridHandle>>`
278278

279-
Optional ref for imperative APIs like scrolling/selecting a cell. See [`DataGridHandle`](#datagridhandle).
279+
Optional ref for imperative APIs like scrolling to or focusing a cell. See [`DataGridHandle`](#datagridhandle).
280280

281281
###### `topSummaryRows?: Maybe<readonly SR[]>`
282282

@@ -507,11 +507,9 @@ function MyGrid() {
507507
}
508508
```
509509

510-
###### `onFill?: Maybe<(event: FillEvent<R>) => R>`
511-
512510
###### `onCellMouseDown?: CellMouseEventHandler<R, SR>`
513511

514-
Callback triggered when a pointer becomes active in a cell. The default behavior is to select the cell. Call `preventGridDefault` to prevent the default behavior.
512+
Callback triggered when a pointer becomes active in a cell. The default behavior is to focus the cell. Call `preventGridDefault` to prevent the default behavior.
515513

516514
```tsx
517515
function onCellMouseDown(args: CellMouseArgs<R, SR>, event: CellMouseEvent) {
@@ -542,7 +540,7 @@ This event can be used to open cell editor on single click
542540
```tsx
543541
function onCellClick(args: CellMouseArgs<R, SR>, event: CellMouseEvent) {
544542
if (args.column.key === 'id') {
545-
args.selectCell(true);
543+
args.setActivePosition(true);
546544
}
547545
}
548546
```
@@ -586,7 +584,7 @@ A function called when keydown event is triggered on a cell. This event can be u
586584

587585
```tsx
588586
function onCellKeyDown(args: CellKeyDownArgs<R, SR>, event: CellKeyboardEvent) {
589-
if (args.mode === 'SELECT' && event.key === 'Enter') {
587+
if (args.mode === 'ACTIVE' && event.key === 'Enter') {
590588
event.preventGridDefault();
591589
}
592590
}
@@ -596,7 +594,7 @@ function onCellKeyDown(args: CellKeyDownArgs<R, SR>, event: CellKeyboardEvent) {
596594

597595
```tsx
598596
function onCellKeyDown(args: CellKeyDownArgs<R, SR>, event: CellKeyboardEvent) {
599-
if (args.mode === 'SELECT' && event.key === 'Tab') {
597+
if (args.mode === 'ACTIVE' && event.key === 'Tab') {
600598
event.preventGridDefault();
601599
}
602600
}
@@ -614,15 +612,13 @@ Callback triggered when content is pasted into a cell.
614612

615613
Return the updated row; the grid will call `onRowsChange` with it.
616614

617-
###### `onSelectedCellChange?: Maybe<(args: CellSelectArgs<R, SR>) => void>`
615+
###### `onActivePositionChange?: Maybe<(args: PositionChangeArgs<R, SR>) => void>`
618616

619-
Triggered when the selected cell is changed.
617+
Triggered when the active position changes.
620618

621-
Arguments:
619+
See the [`PositionChangeArgs`](#positionchangeargstrow-tsummaryrow) type in the Types section below.
622620

623-
- `args.rowIdx`: `number` - row index
624-
- `args.row`: `R | undefined` - row object of the currently selected cell
625-
- `args.column`: `CalculatedColumn<TRow, TSummaryRow>` - column object of the currently selected cell
621+
###### `onFill?: Maybe<(event: FillEvent<R>) => R>`
626622

627623
###### `onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>`
628624

@@ -1374,7 +1370,7 @@ Control whether cells can be edited with `renderEditCell`.
13741370

13751371
##### `colSpan?: Maybe<(args: ColSpanArgs<TRow, TSummaryRow>) => Maybe<number>>`
13761372

1377-
Function to determine how many columns this cell should span. Returns the number of columns to span, or `undefined` for no spanning. See the `ColSpanArgs` type in the Types section below.
1373+
Function to determine how many columns this cell should span. Returns the number of columns to span, or `undefined` for no spanning. See the [`ColSpanArgs`](#colspanargstrow-tsummaryrow) type in the Types section below.
13781374

13791375
**Example:**
13801376

@@ -1587,7 +1583,7 @@ interface RenderEditCellContentProps<TRow, TSummaryRow = unknown> {
15871583
row: TRow;
15881584
rowIdx: number;
15891585
onRowChange: (row: TRow, commitChanges?: boolean) => void;
1590-
onClose: (commitChanges?: boolean, shouldFocusCell?: boolean) => void;
1586+
onClose: (commitChanges?: boolean, shouldFocus?: boolean) => void;
15911587
}
15921588
```
15931589

@@ -1643,17 +1639,17 @@ Props passed to custom row renderers.
16431639
```tsx
16441640
interface RenderRowProps<TRow, TSummaryRow = unknown> {
16451641
row: TRow;
1646-
viewportColumns: readonly CalculatedColumn<TRow, TSummaryRow>[];
1642+
iterateOverViewportColumnsForRow: IterateOverViewportColumnsForRow<TRow, TSummaryRow>;
16471643
rowIdx: number;
1648-
selectedCellIdx: number | undefined;
1649-
isRowSelected: boolean;
1644+
activeCellIdx: number | undefined;
16501645
isRowSelectionDisabled: boolean;
1646+
isRowSelected: boolean;
16511647
gridRowStart: number;
1652-
lastFrozenColumnIndex: number;
16531648
draggedOverCellIdx: number | undefined;
1654-
selectedCellEditor: ReactElement<EditCellProps<TRow, TSummaryRow>> | undefined;
1649+
activeCellEditor: ReactElement<EditCellProps<TRow, TSummaryRow>> | undefined;
16551650
onRowChange: (column: CalculatedColumn<TRow, TSummaryRow>, rowIdx: number, newRow: TRow) => void;
16561651
rowClass: Maybe<(row: TRow, rowIdx: number) => Maybe<string>>;
1652+
isTreeGrid: boolean;
16571653
// ... and event handlers
16581654
}
16591655
```
@@ -1662,7 +1658,7 @@ interface RenderRowProps<TRow, TSummaryRow = unknown> {
16621658

16631659
Props passed to the cell renderer when using `renderers.renderCell`.
16641660

1665-
Shares a base type with row render props (DOM props and cell event handlers) but only includes cell-specific fields like `column`, `row`, `rowIdx`, `colSpan`, and selection state.
1661+
Shares a base type with row render props (DOM props and cell event handlers) but only includes cell-specific fields like `column`, `row`, `rowIdx`, `colSpan`, and position state.
16661662

16671663
#### `Renderers<TRow, TSummaryRow>`
16681664

@@ -1684,37 +1680,25 @@ Arguments passed to cell mouse event handlers.
16841680

16851681
```tsx
16861682
interface CellMouseArgs<TRow, TSummaryRow = unknown> {
1683+
/** The column object of the cell. */
16871684
column: CalculatedColumn<TRow, TSummaryRow>;
1685+
/** The row object of the cell. */
16881686
row: TRow;
1687+
/** The row index of the cell. */
16891688
rowIdx: number;
1690-
selectCell: (enableEditor?: boolean) => void;
1689+
/** Function to manually focus the cell. Pass `true` to immediately start editing. */
1690+
setActivePosition: (enableEditor?: boolean) => void;
16911691
}
16921692
```
16931693

1694-
##### `column: CalculatedColumn<TRow, TSummaryRow>`
1695-
1696-
The column object of the cell.
1697-
1698-
##### `row: TRow`
1699-
1700-
The row object of the cell.
1701-
1702-
##### `rowIdx: number`
1703-
1704-
The row index of the cell.
1705-
1706-
##### `selectCell: (enableEditor?: boolean) => void`
1707-
1708-
Function to manually select the cell. Pass `true` to immediately start editing.
1709-
17101694
**Example:**
17111695

17121696
```tsx
17131697
import type { CellMouseArgs, CellMouseEvent } from 'react-data-grid';
17141698

17151699
function onCellClick(args: CellMouseArgs<Row>, event: CellMouseEvent) {
17161700
console.log('Clicked cell at row', args.rowIdx, 'column', args.column.key);
1717-
args.selectCell(true); // Select and start editing
1701+
args.setActivePosition(true); // Focus and start editing
17181702
}
17191703
```
17201704

@@ -1747,7 +1731,7 @@ import type { CellMouseArgs, CellMouseEvent } from 'react-data-grid';
17471731

17481732
function onCellClick(args: CellMouseArgs<Row>, event: CellMouseEvent) {
17491733
if (args.column.key === 'actions') {
1750-
event.preventGridDefault(); // Prevent cell selection
1734+
event.preventGridDefault(); // Prevent cell focus
17511735
}
17521736
}
17531737
```
@@ -1774,17 +1758,17 @@ type CellClipboardEvent = React.ClipboardEvent<HTMLDivElement>;
17741758

17751759
#### `CellKeyDownArgs<TRow, TSummaryRow>`
17761760

1777-
Arguments passed to the `onCellKeyDown` handler. The shape differs based on whether the cell is in SELECT or EDIT mode.
1761+
Arguments passed to the `onCellKeyDown` handler. The shape differs based on whether the cell is in ACTIVE or EDIT mode.
17781762

1779-
**SELECT mode:**
1763+
**ACTIVE mode:**
17801764

17811765
```tsx
1782-
interface SelectCellKeyDownArgs<TRow, TSummaryRow = unknown> {
1783-
mode: 'SELECT';
1766+
interface ActiveCellKeyDownArgs<TRow, TSummaryRow = unknown> {
1767+
mode: 'ACTIVE';
17841768
column: CalculatedColumn<TRow, TSummaryRow> | undefined;
1785-
row: TRow;
1769+
row: TRow | undefined;
17861770
rowIdx: number;
1787-
selectCell: (position: Position, options?: SelectCellOptions) => void;
1771+
setActivePosition: (position: Position, options?: SetActivePositionOptions) => void;
17881772
}
17891773
```
17901774

@@ -1797,7 +1781,7 @@ interface EditCellKeyDownArgs<TRow, TSummaryRow = unknown> {
17971781
row: TRow;
17981782
rowIdx: number;
17991783
navigate: () => void;
1800-
onClose: (commitChanges?: boolean, shouldFocusCell?: boolean) => void;
1784+
onClose: (commitChanges?: boolean, shouldFocus?: boolean) => void;
18011785
}
18021786
```
18031787

@@ -1814,15 +1798,24 @@ function onCellKeyDown(args: CellKeyDownArgs<Row>, event: CellKeyboardEvent) {
18141798
}
18151799
```
18161800

1817-
#### `CellSelectArgs<TRow, TSummaryRow>`
1801+
#### `PositionChangeArgs<TRow, TSummaryRow>`
18181802

1819-
Arguments passed to `onSelectedCellChange`.
1803+
Arguments passed to `onActivePositionChange`.
18201804

18211805
```tsx
1822-
interface CellSelectArgs<TRow, TSummaryRow = unknown> {
1806+
interface PositionChangeArgs<TRow, TSummaryRow = unknown> {
1807+
/** row index of the active position */
18231808
rowIdx: number;
1809+
/**
1810+
* row object of the active position,
1811+
* undefined if the active position is on a header or summary row
1812+
*/
18241813
row: TRow | undefined;
1825-
column: CalculatedColumn<TRow, TSummaryRow>;
1814+
/**
1815+
* column object of the active position,
1816+
* undefined if the active position is a row instead of a cell
1817+
*/
1818+
column: CalculatedColumn<TRow, TSummaryRow> | undefined;
18261819
}
18271820
```
18281821

@@ -1854,9 +1847,9 @@ Arguments passed to the `colSpan` function.
18541847

18551848
```tsx
18561849
type ColSpanArgs<TRow, TSummaryRow> =
1857-
| { type: 'HEADER' }
1858-
| { type: 'ROW'; row: TRow }
1859-
| { type: 'SUMMARY'; row: TSummaryRow };
1850+
| { readonly type: 'HEADER' }
1851+
| { readonly type: 'ROW'; readonly row: TRow }
1852+
| { readonly type: 'SUMMARY'; readonly row: TSummaryRow };
18601853
```
18611854

18621855
**Example:**
@@ -1989,14 +1982,14 @@ interface Position {
19891982
}
19901983
```
19911984

1992-
#### `SelectCellOptions`
1985+
#### `SetActivePositionOptions`
19931986

1994-
Options for programmatically selecting a cell.
1987+
Options for programmatically updating the grid's active position.
19951988

19961989
```tsx
1997-
interface SelectCellOptions {
1990+
interface SetActivePositionOptions {
19981991
enableEditor?: Maybe<boolean>;
1999-
shouldFocusCell?: Maybe<boolean>;
1992+
shouldFocus?: Maybe<boolean>;
20001993
}
20011994
```
20021995

@@ -2054,8 +2047,8 @@ Handle type assigned to a grid's `ref` for programmatic grid control.
20542047
```tsx
20552048
interface DataGridHandle {
20562049
element: HTMLDivElement | null;
2057-
scrollToCell: (position: Partial<Position>) => void;
2058-
selectCell: (position: Position, options?: SelectCellOptions) => void;
2050+
scrollToCell: (position: PartialPosition) => void;
2051+
setActivePosition: (position: Position, options?: SetActivePositionOptions) => void;
20592052
}
20602053
```
20612054

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"typecheck": "tsc --build"
4848
},
4949
"devDependencies": {
50-
"@eslint-react/eslint-plugin": "3.0.0-beta.68",
50+
"@eslint-react/eslint-plugin": "3.0.0-next.71",
5151
"@eslint/markdown": "^7.5.1",
5252
"@faker-js/faker": "^10.0.0",
5353
"@tanstack/react-router": "^1.132.31",

src/Cell.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const cellDraggedOverClassname = `rdg-cell-dragged-over ${cellDraggedOver}`;
1616
function Cell<R, SR>({
1717
column,
1818
colSpan,
19-
isCellSelected,
19+
isCellActive,
2020
isDraggedOver,
2121
row,
2222
rowIdx,
@@ -30,11 +30,11 @@ function Cell<R, SR>({
3030
onContextMenu,
3131
onCellContextMenu,
3232
onRowChange,
33-
selectCell,
33+
setActivePosition,
3434
style,
3535
...props
3636
}: RenderCellProps<R, SR>) {
37-
const { tabIndex, childTabIndex, onFocus } = useRovingTabIndex(isCellSelected);
37+
const { tabIndex, childTabIndex, onFocus } = useRovingTabIndex(isCellActive);
3838

3939
const { cellClass } = column;
4040
className = getCellClassname(
@@ -47,8 +47,8 @@ function Cell<R, SR>({
4747
);
4848
const isEditable = isCellEditableUtil(column, row);
4949

50-
function selectCellWrapper(enableEditor?: boolean) {
51-
selectCell({ rowIdx, idx: column.idx }, { enableEditor });
50+
function setActivePositionWrapper(enableEditor?: boolean) {
51+
setActivePosition({ rowIdx, idx: column.idx }, { enableEditor });
5252
}
5353

5454
function handleMouseEvent(
@@ -58,7 +58,7 @@ function Cell<R, SR>({
5858
let eventHandled = false;
5959
if (eventHandler) {
6060
const cellEvent = createCellEvent(event);
61-
eventHandler({ rowIdx, row, column, selectCell: selectCellWrapper }, cellEvent);
61+
eventHandler({ rowIdx, row, column, setActivePosition: setActivePositionWrapper }, cellEvent);
6262
eventHandled = cellEvent.isGridDefaultPrevented();
6363
}
6464
return eventHandled;
@@ -68,7 +68,7 @@ function Cell<R, SR>({
6868
onMouseDown?.(event);
6969
if (!handleMouseEvent(event, onCellMouseDown)) {
7070
// select cell if the event is not prevented
71-
selectCellWrapper();
71+
setActivePositionWrapper();
7272
}
7373
}
7474

@@ -81,7 +81,7 @@ function Cell<R, SR>({
8181
onDoubleClick?.(event);
8282
if (!handleMouseEvent(event, onCellDoubleClick)) {
8383
// go into edit mode if the event is not prevented
84-
selectCellWrapper(true);
84+
setActivePositionWrapper(true);
8585
}
8686
}
8787

@@ -91,15 +91,15 @@ function Cell<R, SR>({
9191
}
9292

9393
function handleRowChange(newRow: R) {
94-
onRowChange(column, newRow);
94+
onRowChange(column, rowIdx, newRow);
9595
}
9696

9797
return (
9898
<div
9999
role="gridcell"
100100
aria-colindex={column.idx + 1} // aria-colindex is 1-based
101101
aria-colspan={colSpan}
102-
aria-selected={isCellSelected}
102+
aria-selected={isCellActive}
103103
aria-readonly={!isEditable || undefined}
104104
tabIndex={tabIndex}
105105
className={className}

0 commit comments

Comments
 (0)