@absreim/react-bootstrap-data-grid-pro 4.6.0 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grid/focus/types.d.ts +4 -2
- package/grid/focus/useGridFocus.js +20 -20
- package/grid/main/Grid.js +1 -1
- package/grid/main/GridBody.js +8 -7
- package/grid/main/GridHeader.js +1 -1
- package/package.json +1 -1
package/grid/focus/types.d.ts
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export interface FocusCoordinates {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* An index like ARIA row index, except that it is based on the actual
|
|
9
|
+
* position of the row. When pagination is enabled, this value can differ from
|
|
10
|
+
* the ARIA row index.
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
displayRowIndex: number;
|
|
11
13
|
/**
|
|
12
14
|
* The ARIA column index.
|
|
13
15
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState, } from "react";
|
|
2
2
|
const startingCoordinates = {
|
|
3
3
|
ariaColIndex: 1,
|
|
4
|
-
|
|
4
|
+
displayRowIndex: 1,
|
|
5
5
|
};
|
|
6
6
|
const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
7
7
|
const [coords, setCoords] = useState(startingCoordinates);
|
|
@@ -9,14 +9,14 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
9
9
|
// be a prop here to update effective coordinates at the appropriate times.
|
|
10
10
|
const effectiveCoords = useMemo(() => ({
|
|
11
11
|
ariaColIndex: Math.min(coords.ariaColIndex, numCols),
|
|
12
|
-
|
|
13
|
-
}), [coords.ariaColIndex, coords.
|
|
12
|
+
displayRowIndex: Math.min(coords.displayRowIndex, numRows),
|
|
13
|
+
}), [coords.ariaColIndex, coords.displayRowIndex, numCols, numRows]);
|
|
14
14
|
const currentCellIsSortableHeader = useMemo(() => {
|
|
15
|
-
if (coords.
|
|
15
|
+
if (coords.displayRowIndex !== 1) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
return sortableColIndices.includes(coords.ariaColIndex);
|
|
19
|
-
}, [coords.ariaColIndex, coords.
|
|
19
|
+
}, [coords.ariaColIndex, coords.displayRowIndex, sortableColIndices]);
|
|
20
20
|
const gridClickHandler = useCallback((event) => {
|
|
21
21
|
let cursor = event.target;
|
|
22
22
|
while (cursor !== event.currentTarget &&
|
|
@@ -30,26 +30,26 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
30
30
|
}
|
|
31
31
|
const row = cursor.parentElement;
|
|
32
32
|
setCoords({
|
|
33
|
-
ariaColIndex: Number(cursor.getAttribute("aria-
|
|
34
|
-
|
|
33
|
+
ariaColIndex: Number(cursor.getAttribute("aria-colindex")),
|
|
34
|
+
displayRowIndex: Number(row.getAttribute("display-rowindex")),
|
|
35
35
|
});
|
|
36
36
|
}, []);
|
|
37
37
|
const gridKeydownHandler = useCallback((event) => {
|
|
38
38
|
switch (event.code) {
|
|
39
39
|
case "ArrowDown": {
|
|
40
|
-
if (effectiveCoords.
|
|
40
|
+
if (effectiveCoords.displayRowIndex !== numRows) {
|
|
41
41
|
setCoords({
|
|
42
42
|
ariaColIndex: effectiveCoords.ariaColIndex,
|
|
43
|
-
|
|
43
|
+
displayRowIndex: effectiveCoords.displayRowIndex + 1,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
break;
|
|
47
47
|
}
|
|
48
48
|
case "ArrowUp": {
|
|
49
|
-
if (effectiveCoords.
|
|
49
|
+
if (effectiveCoords.displayRowIndex !== 1) {
|
|
50
50
|
setCoords({
|
|
51
51
|
ariaColIndex: effectiveCoords.ariaColIndex,
|
|
52
|
-
|
|
52
|
+
displayRowIndex: effectiveCoords.displayRowIndex - 1,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
break;
|
|
@@ -58,7 +58,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
58
58
|
if (effectiveCoords.ariaColIndex !== 1) {
|
|
59
59
|
setCoords({
|
|
60
60
|
ariaColIndex: effectiveCoords.ariaColIndex - 1,
|
|
61
|
-
|
|
61
|
+
displayRowIndex: effectiveCoords.displayRowIndex,
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
break;
|
|
@@ -67,7 +67,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
67
67
|
if (effectiveCoords.ariaColIndex !== numCols) {
|
|
68
68
|
setCoords({
|
|
69
69
|
ariaColIndex: effectiveCoords.ariaColIndex + 1,
|
|
70
|
-
|
|
70
|
+
displayRowIndex: effectiveCoords.displayRowIndex,
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
break;
|
|
@@ -76,13 +76,13 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
76
76
|
if (event.ctrlKey || event.metaKey) {
|
|
77
77
|
setCoords({
|
|
78
78
|
ariaColIndex: 1,
|
|
79
|
-
|
|
79
|
+
displayRowIndex: 1,
|
|
80
80
|
});
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
setCoords({
|
|
84
84
|
ariaColIndex: 1,
|
|
85
|
-
|
|
85
|
+
displayRowIndex: effectiveCoords.displayRowIndex,
|
|
86
86
|
});
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
@@ -90,13 +90,13 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
90
90
|
if (event.ctrlKey || event.metaKey) {
|
|
91
91
|
setCoords({
|
|
92
92
|
ariaColIndex: numCols,
|
|
93
|
-
|
|
93
|
+
displayRowIndex: numRows,
|
|
94
94
|
});
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
setCoords({
|
|
98
98
|
ariaColIndex: numCols,
|
|
99
|
-
|
|
99
|
+
displayRowIndex: effectiveCoords.displayRowIndex,
|
|
100
100
|
});
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
@@ -109,7 +109,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
109
109
|
// makes in terms of performance vs relying on the useEffect hook.
|
|
110
110
|
}, [
|
|
111
111
|
effectiveCoords.ariaColIndex,
|
|
112
|
-
effectiveCoords.
|
|
112
|
+
effectiveCoords.displayRowIndex,
|
|
113
113
|
numCols,
|
|
114
114
|
numRows,
|
|
115
115
|
]);
|
|
@@ -123,7 +123,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
123
123
|
if (!gridRef.current.contains(document.activeElement)) {
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
const cellSelector = `:scope > div > div[
|
|
126
|
+
const cellSelector = `:scope > div > div[display-rowindex="${effectiveCoords.displayRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`;
|
|
127
127
|
const elToFocus = gridRef.current.querySelector(currentCellIsSortableHeader
|
|
128
128
|
? cellSelector + " .rbdg-grid-header-button"
|
|
129
129
|
: cellSelector);
|
|
@@ -132,7 +132,7 @@ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
|
|
|
132
132
|
}
|
|
133
133
|
}, [
|
|
134
134
|
effectiveCoords.ariaColIndex,
|
|
135
|
-
effectiveCoords.
|
|
135
|
+
effectiveCoords.displayRowIndex,
|
|
136
136
|
gridRef,
|
|
137
137
|
currentCellIsSortableHeader,
|
|
138
138
|
]);
|
package/grid/main/Grid.js
CHANGED
|
@@ -91,7 +91,7 @@ const Grid = ({ rows, cols, sortModel, pagination, allowExport, filterModel, wid
|
|
|
91
91
|
"rbdg-grid-borderless": borders === "none",
|
|
92
92
|
"rbdg-grid-sm": !!small,
|
|
93
93
|
"rbdg-grid-group-divider": !!divider,
|
|
94
|
-
}, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, "data-testid": "rbdg-grid", children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.
|
|
94
|
+
}, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, "data-testid": "rbdg-grid", children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.displayRowIndex === 1
|
|
95
95
|
? effectiveCoords.ariaColIndex
|
|
96
96
|
: null, cellFocusVariant: headerCellFocusVariant, sortInfo: sortedRowsOutput }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
|
|
97
97
|
const getPagination = (pagination) => {
|
package/grid/main/GridBody.js
CHANGED
|
@@ -4,18 +4,19 @@ import classNames from "classnames";
|
|
|
4
4
|
import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
|
|
5
5
|
import { GRID_BODY_DATA_TEST_ID } from "../constants";
|
|
6
6
|
const GridBody = ({ augFormattedRows, cols, rowVariant, cellVariant, focusCoords, cellFocusVariant, }) => {
|
|
7
|
-
return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row,
|
|
7
|
+
return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map((row, displayRowArrayIndex) => {
|
|
8
8
|
const ariaRowIndex = row.prePaginationIndex + 2;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const displayRowIndex = displayRowArrayIndex + 2;
|
|
10
|
+
return (_jsx("div", { role: "row", "display-rowindex": displayRowIndex, "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
|
|
11
|
+
rowVariant(row, displayRowArrayIndex) &&
|
|
12
|
+
`${CSS_PREFIX}-${rowVariant(row, displayRowArrayIndex)}`), children: row.contents.map(({ formattedValue, width }, index) => {
|
|
12
13
|
const ariaColIndex = index + 1;
|
|
13
14
|
const isFocused = focusCoords.ariaColIndex === ariaColIndex &&
|
|
14
|
-
focusCoords.
|
|
15
|
+
focusCoords.displayRowIndex === displayRowIndex;
|
|
15
16
|
const cellVariantVal = cellVariant &&
|
|
16
|
-
cellVariant(row.contents[index], row, index,
|
|
17
|
+
cellVariant(row.contents[index], row, index, displayRowArrayIndex);
|
|
17
18
|
const cellFocusVariantVal = cellFocusVariant &&
|
|
18
|
-
cellFocusVariant(row.contents[index], row, index,
|
|
19
|
+
cellFocusVariant(row.contents[index], row, index, displayRowArrayIndex);
|
|
19
20
|
return (_jsx("div", { tabIndex: isFocused ? 0 : -1, style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariantVal && `${CSS_PREFIX}-${cellVariantVal}`, cellFocusVariantVal && `focus-ring-${cellFocusVariantVal}`, {
|
|
20
21
|
"z-2": isFocused,
|
|
21
22
|
"rbdg-focusable-cell": isFocused,
|
package/grid/main/GridHeader.js
CHANGED
|
@@ -24,7 +24,7 @@ const GridHeader = ({ cols, vertScrollable, rowVariant, cellVariant, focusColInd
|
|
|
24
24
|
}
|
|
25
25
|
setSortColDef(null);
|
|
26
26
|
};
|
|
27
|
-
return (_jsx("div", { "data-testid": GRID_HEADER_DATA_TEST_ID, role: "rowgroup", className: classNames(vertScrollable ? ["position-sticky", "z-1", "top-0"] : []), children: _jsx("div", { role: "row", className: classNames("d-flex", "flex-row", rowVariant && `${CSS_PREFIX}-${rowVariant}`), "aria-rowindex": 1, children: cols.map((col, index) => {
|
|
27
|
+
return (_jsx("div", { "data-testid": GRID_HEADER_DATA_TEST_ID, role: "rowgroup", className: classNames(vertScrollable ? ["position-sticky", "z-1", "top-0"] : []), children: _jsx("div", { role: "row", className: classNames("d-flex", "flex-row", rowVariant && `${CSS_PREFIX}-${rowVariant}`), "display-rowindex": 1, "aria-rowindex": 1, children: cols.map((col, index) => {
|
|
28
28
|
const ariaColIndex = index + 1;
|
|
29
29
|
const isFocused = focusColIndex === ariaColIndex;
|
|
30
30
|
const cellVariantVal = cellVariant && cellVariant(col, index);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absreim/react-bootstrap-data-grid-pro",
|
|
3
3
|
"description": "Pro Version of data grid UI component for use with web apps using React and Bootstrap",
|
|
4
|
-
"version": "4.6.
|
|
4
|
+
"version": "4.6.1",
|
|
5
5
|
"license": "Commercial. See LICENSE file.",
|
|
6
6
|
"author": "Brook Li",
|
|
7
7
|
"homepage": "https://react-bootstrap-data-grid.vercel.app/",
|