Skip to content

Commit

Permalink
fix(flat-table): ensure window does not scroll when using up and down…
Browse files Browse the repository at this point in the history
… arrow keys to navigate rows

Ensure the default browser behaviour is prevented when using up and down arrow keys to navigate
clickable/ expandable rows

fix #6152
  • Loading branch information
edleeks87 committed Jun 29, 2023
1 parent a742bd4 commit ea89c65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/flat-table/flat-table.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const FlatTable = ({
);

if (Events.isDownKey(ev)) {
ev.preventDefault();
if (
currentFocusIndex !== -1 &&
currentFocusIndex < focusableElementsArray.length
Expand All @@ -153,6 +154,7 @@ const FlatTable = ({
}
}
} else if (Events.isUpKey(ev)) {
ev.preventDefault();
if (currentFocusIndex > 0) {
focusableElementsArray[currentFocusIndex - 1]?.focus();
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/components/flat-table/flat-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,9 @@ describe("FlatTable", () => {
});

describe("keyboard navigation", () => {
const arrowDown = { key: "ArrowDown" };
const arrowUp = { key: "ArrowUp" };
const preventDefault = jest.fn();
const arrowDown = { key: "ArrowDown", preventDefault };
const arrowUp = { key: "ArrowUp", preventDefault };
const arrowLeft = { key: "ArrowLeft" };

describe("when rows are clickable", () => {
Expand Down

0 comments on commit ea89c65

Please sign in to comment.