Skip to content

Commit

Permalink
Merge pull request #6153 from Sage/add-prevent-default-to-ft-keyboard…
Browse files Browse the repository at this point in the history
…-nav

fix(flat-table): ensure window does not scroll when using up and down  arrow keys to navigate rows
  • Loading branch information
edleeks87 authored Jun 29, 2023
2 parents a742bd4 + ea89c65 commit a28fe54
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 a28fe54

Please sign in to comment.