@absreim/react-bootstrap-data-grid 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
|
var startingCoordinates = {
|
|
3
3
|
ariaColIndex: 1,
|
|
4
|
-
|
|
4
|
+
displayRowIndex: 1,
|
|
5
5
|
};
|
|
6
6
|
var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
|
|
7
7
|
var _a = useState(startingCoordinates), coords = _a[0], setCoords = _a[1];
|
|
@@ -9,14 +9,14 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
|
|
|
9
9
|
// be a prop here to update effective coordinates at the appropriate times.
|
|
10
10
|
var effectiveCoords = useMemo(function () { return ({
|
|
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
|
var currentCellIsSortableHeader = useMemo(function () {
|
|
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
|
var gridClickHandler = useCallback(function (event) {
|
|
21
21
|
var cursor = event.target;
|
|
22
22
|
while (cursor !== event.currentTarget &&
|
|
@@ -30,26 +30,26 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
|
|
|
30
30
|
}
|
|
31
31
|
var 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
|
var gridKeydownHandler = useCallback(function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (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 @@ var useGridFocus = function (gridRef, numRows, numCols, sortableColIndices) {
|
|
|
123
123
|
if (!gridRef.current.contains(document.activeElement)) {
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
var cellSelector = ":scope > div > div[
|
|
126
|
+
var cellSelector = ":scope > div > div[display-rowindex=\"".concat(effectiveCoords.displayRowIndex, "\"] > div[aria-colindex=\"").concat(effectiveCoords.ariaColIndex, "\"]");
|
|
127
127
|
var elToFocus = gridRef.current.querySelector(currentCellIsSortableHeader
|
|
128
128
|
? cellSelector + " .rbdg-grid-header-button"
|
|
129
129
|
: cellSelector);
|
|
@@ -132,7 +132,7 @@ var useGridFocus = function (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
|
@@ -92,7 +92,7 @@ var Grid = function (_a) {
|
|
|
92
92
|
"rbdg-grid-borderless": borders === "none",
|
|
93
93
|
"rbdg-grid-sm": !!small,
|
|
94
94
|
"rbdg-grid-group-divider": !!divider,
|
|
95
|
-
}, "rbdg-grid", variant && "".concat(CSS_PREFIX, "-").concat(variant), borderVariant && "border-".concat(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.
|
|
95
|
+
}, "rbdg-grid", variant && "".concat(CSS_PREFIX, "-").concat(variant), borderVariant && "border-".concat(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
|
|
96
96
|
? effectiveCoords.ariaColIndex
|
|
97
97
|
: null, cellFocusVariant: headerCellFocusVariant, sortInfo: sortedRowsOutput }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
|
|
98
98
|
var getPagination = function (pagination) {
|
package/grid/main/GridBody.js
CHANGED
|
@@ -5,19 +5,20 @@ import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
|
|
|
5
5
|
import { GRID_BODY_DATA_TEST_ID } from "../constants";
|
|
6
6
|
var GridBody = function (_a) {
|
|
7
7
|
var augFormattedRows = _a.augFormattedRows, cols = _a.cols, rowVariant = _a.rowVariant, cellVariant = _a.cellVariant, focusCoords = _a.focusCoords, cellFocusVariant = _a.cellFocusVariant;
|
|
8
|
-
return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map(function (row,
|
|
8
|
+
return (_jsx("div", { role: "rowgroup", "data-testid": GRID_BODY_DATA_TEST_ID, children: augFormattedRows.map(function (row, displayRowArrayIndex) {
|
|
9
9
|
var ariaRowIndex = row.prePaginationIndex + 2;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
var displayRowIndex = displayRowArrayIndex + 2;
|
|
11
|
+
return (_jsx("div", { role: "row", "display-rowindex": displayRowIndex, "aria-rowindex": ariaRowIndex, className: classNames("d-flex", "flex-row", rowVariant &&
|
|
12
|
+
rowVariant(row, displayRowArrayIndex) &&
|
|
13
|
+
"".concat(CSS_PREFIX, "-").concat(rowVariant(row, displayRowArrayIndex))), children: row.contents.map(function (_a, index) {
|
|
13
14
|
var formattedValue = _a.formattedValue, width = _a.width;
|
|
14
15
|
var ariaColIndex = index + 1;
|
|
15
16
|
var isFocused = focusCoords.ariaColIndex === ariaColIndex &&
|
|
16
|
-
focusCoords.
|
|
17
|
+
focusCoords.displayRowIndex === displayRowIndex;
|
|
17
18
|
var cellVariantVal = cellVariant &&
|
|
18
|
-
cellVariant(row.contents[index], row, index,
|
|
19
|
+
cellVariant(row.contents[index], row, index, displayRowArrayIndex);
|
|
19
20
|
var cellFocusVariantVal = cellFocusVariant &&
|
|
20
|
-
cellFocusVariant(row.contents[index], row, index,
|
|
21
|
+
cellFocusVariant(row.contents[index], row, index, displayRowArrayIndex);
|
|
21
22
|
return (_jsx("div", { tabIndex: isFocused ? 0 : -1, style: getWidthStyles(width || DEFAULT_COL_WIDTH), role: "gridcell", className: classNames("rbdg-grid-cell", cellVariantVal && "".concat(CSS_PREFIX, "-").concat(cellVariantVal), cellFocusVariantVal && "focus-ring-".concat(cellFocusVariantVal), {
|
|
22
23
|
"z-2": isFocused,
|
|
23
24
|
"rbdg-focusable-cell": isFocused,
|
package/grid/main/GridHeader.js
CHANGED
|
@@ -25,7 +25,7 @@ var GridHeader = function (_a) {
|
|
|
25
25
|
}
|
|
26
26
|
setSortColDef(null);
|
|
27
27
|
}; };
|
|
28
|
-
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 && "".concat(CSS_PREFIX, "-").concat(rowVariant)), "aria-rowindex": 1, children: cols.map(function (col, index) {
|
|
28
|
+
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 && "".concat(CSS_PREFIX, "-").concat(rowVariant)), "display-rowindex": 1, "aria-rowindex": 1, children: cols.map(function (col, index) {
|
|
29
29
|
var ariaColIndex = index + 1;
|
|
30
30
|
var isFocused = focusColIndex === ariaColIndex;
|
|
31
31
|
var cellVariantVal = cellVariant && cellVariant(col, index);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absreim/react-bootstrap-data-grid",
|
|
3
3
|
"description": "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": "MIT",
|
|
6
6
|
"author": "Brook Li",
|
|
7
7
|
"homepage": "https://react-bootstrap-data-grid.vercel.app/",
|