Skip to content

fix(AnalyticalTable): fix keyboard navigation for RTL text direction #4990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const navigateFromActiveSubCompItem = (currentlyFocusedCell, e) => {
setFocus(currentlyFocusedCell, recursiveSubComponentElementSearch(e.target));
};

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

const onKeyboardNavigation = useCallback(
(e) => {
const { isRtl } = state;
const isActiveItemInSubComponent = e.target.dataset.subcomponentActiveElement;
// check if target is cell and if so proceed from there
if (
Expand Down Expand Up @@ -228,7 +229,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
return;
}
const newElement = tableRef.current.querySelector(
`div[data-column-index="${columnIndex + 1}"][data-row-index="${rowIndex}"]`
`div[data-column-index="${columnIndex + (isRtl ? -1 : 1)}"][data-row-index="${rowIndex}"]`
);
if (newElement) {
setFocus(currentlyFocusedCell, newElement);
Expand All @@ -244,7 +245,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
return;
}
const newElement = tableRef.current.querySelector(
`div[data-column-index="${columnIndex - 1}"][data-row-index="${rowIndex}"]`
`div[data-column-index="${columnIndex - (isRtl ? -1 : 1)}"][data-row-index="${rowIndex}"]`
);
if (newElement) {
setFocus(currentlyFocusedCell, newElement);
Expand Down Expand Up @@ -309,7 +310,7 @@ const useGetTableProps = (tableProps, { instance: { webComponentsReactProperties
}
}
},
[currentlyFocusedCell.current, tableRef.current]
[currentlyFocusedCell.current, tableRef.current, state?.isRtl]
);
if (showOverlay) {
return tableProps;
Expand Down