Skip to content

Commit 84d21d7

Browse files
authored
fix(AnalyticalTable): fix keyboard navigation for RTL text direction (#4990)
1 parent 63652bd commit 84d21d7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/main/src/components/AnalyticalTable/hooks/useKeyboardNavigation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const navigateFromActiveSubCompItem = (currentlyFocusedCell, e) => {
6161
setFocus(currentlyFocusedCell, recursiveSubComponentElementSearch(e.target));
6262
};
6363

64-
const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties, data, columns } }) => {
64+
const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties, data, columns, state } }) => {
6565
const { showOverlay, tableRef } = webComponentsReactProperties;
6666
const currentlyFocusedCell = useRef<HTMLDivElement>(null);
6767
const noData = data.length === 0;
@@ -143,6 +143,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
143143

144144
const onKeyboardNavigation = useCallback(
145145
(e) => {
146+
const { isRtl } = state;
146147
const isActiveItemInSubComponent = e.target.dataset.subcomponentActiveElement;
147148
// check if target is cell and if so proceed from there
148149
if (
@@ -228,7 +229,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
228229
return;
229230
}
230231
const newElement = tableRef.current.querySelector(
231-
`div[data-column-index="${columnIndex + 1}"][data-row-index="${rowIndex}"]`
232+
`div[data-column-index="${columnIndex + (isRtl ? -1 : 1)}"][data-row-index="${rowIndex}"]`
232233
);
233234
if (newElement) {
234235
setFocus(currentlyFocusedCell, newElement);
@@ -244,7 +245,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
244245
return;
245246
}
246247
const newElement = tableRef.current.querySelector(
247-
`div[data-column-index="${columnIndex - 1}"][data-row-index="${rowIndex}"]`
248+
`div[data-column-index="${columnIndex - (isRtl ? -1 : 1)}"][data-row-index="${rowIndex}"]`
248249
);
249250
if (newElement) {
250251
setFocus(currentlyFocusedCell, newElement);
@@ -309,7 +310,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
309310
}
310311
}
311312
},
312-
[currentlyFocusedCell.current, tableRef.current]
313+
[currentlyFocusedCell.current, tableRef.current, state?.isRtl]
313314
);
314315
if (showOverlay) {
315316
return tableProps;

0 commit comments

Comments
 (0)