diff --git a/src/components/GridKeyboardNavigationContext/GridKeyboardNavigationContext.js b/src/components/GridKeyboardNavigationContext/GridKeyboardNavigationContext.js
index ad43be448d..009e19c680 100644
--- a/src/components/GridKeyboardNavigationContext/GridKeyboardNavigationContext.js
+++ b/src/components/GridKeyboardNavigationContext/GridKeyboardNavigationContext.js
@@ -3,6 +3,7 @@ import useEventListener from "../../hooks/useEventListener";
import {
focusElementWithDirection,
getDirectionMaps,
+ getNextElementToFocusInDirection,
getOppositeDirection,
getOutmostElementInDirection
} from "./helper";
@@ -34,8 +35,8 @@ export const useGridKeyboardNavigationContext = (positions, wrapperRef) => {
const onOutboundNavigation = useCallback(
(elementRef, direction) => {
- const maybeNextElement = directionMaps[direction].get(elementRef);
- if (maybeNextElement?.current) {
+ const maybeNextElement = getNextElementToFocusInDirection(directionMaps[direction], elementRef);
+ if (maybeNextElement) {
elementRef.current?.blur();
focusElementWithDirection(maybeNextElement, direction);
return;
diff --git a/src/components/GridKeyboardNavigationContext/__stories__/useGridKeyboardNavigationContext.stories.js b/src/components/GridKeyboardNavigationContext/__stories__/useGridKeyboardNavigationContext.stories.js
index 4377f90acd..2bbaf9a5ee 100644
--- a/src/components/GridKeyboardNavigationContext/__stories__/useGridKeyboardNavigationContext.stories.js
+++ b/src/components/GridKeyboardNavigationContext/__stories__/useGridKeyboardNavigationContext.stories.js
@@ -12,7 +12,7 @@ const PADDING_PX = 24;
const ON_CLICK = action("Selected");
-export const DummyNavigableGrid = forwardRef(({ itemsCount, numberOfItemsInLine, itemPrefix }, ref) => {
+export const DummyNavigableGrid = forwardRef(({ itemsCount, numberOfItemsInLine, itemPrefix, disabled }, ref) => {
const width = useMemo(() => numberOfItemsInLine * ELEMENT_WIDTH_PX + 2 * PADDING_PX, [numberOfItemsInLine]);
const items = useMemo(() => range(itemsCount).map(num => `${itemPrefix} ${num}`), [itemPrefix, itemsCount]);
const getItemByIndex = useCallback(index => items[index], [items]);
@@ -25,12 +25,19 @@ export const DummyNavigableGrid = forwardRef(({ itemsCount, numberOfItemsInLine,
});
const onClickByIndex = useCallback(index => () => onSelectionAction(index), [onSelectionAction]);
return (
-
+
{items.map((item, index) => (