From 82588de7bf8a7433fd2fc69d39b8c8a12939aa1e Mon Sep 17 00:00:00 2001 From: Omri Lavi Date: Wed, 26 Jan 2022 17:25:58 +0200 Subject: [PATCH] Disabled indexes for keyboard nav (#493) * added disabled indexes support + tests * updated storybook --- .../useGridKeyboardNavigation.stories.mdx | 10 ++- .../gridKeyboardNavigationHelper.jest.js | 78 +++++++++++++++++++ .../useGridKeyboardNavigation.jest.js | 24 +++++- .../gridKeyboardNavigationHelper.js | 22 +++++- .../useGridKeyboardNavigation.js | 7 +- 5 files changed, 135 insertions(+), 6 deletions(-) diff --git a/src/hooks/useGridKeyboardNavigation/__stories__/useGridKeyboardNavigation.stories.mdx b/src/hooks/useGridKeyboardNavigation/__stories__/useGridKeyboardNavigation.stories.mdx index 9e3696f2d5..9ed931f6bb 100644 --- a/src/hooks/useGridKeyboardNavigation/__stories__/useGridKeyboardNavigation.stories.mdx +++ b/src/hooks/useGridKeyboardNavigation/__stories__/useGridKeyboardNavigation.stories.mdx @@ -30,6 +30,7 @@ export const ON_CLICK = action("item selected"); {() => { const ref = useRef(null); + const disabledIndexes = [2, 4, 6]; const [itemsCount, setItemsCount] = useState(15); const [numberOfItemsInLine, setNumberOfItemsInLine] = useState(4); const width = useMemo(() => numberOfItemsInLine * ELEMENT_WIDTH_PX + 2 * PADDING_PX, [numberOfItemsInLine]); @@ -40,7 +41,8 @@ export const ON_CLICK = action("item selected"); numberOfItemsInLine, itemsCount, getItemByIndex, - onItemClicked: ON_CLICK + onItemClicked: ON_CLICK, + disabledIndexes }); const onClickByIndex = useCallback(index => () => onSelectionAction(index), [onSelectionAction]); return ( @@ -49,6 +51,7 @@ export const ON_CLICK = action("item selected"); {items.map((item, index) => (