From 7aaaa73fddb3c8434104785f65268ee373079634 Mon Sep 17 00:00:00 2001 From: Rivka Ungar Date: Thu, 12 Dec 2024 15:34:28 +0200 Subject: [PATCH] fix(List): getting wrong tabIndex on initialization (#2648) --- packages/core/src/components/List/List.tsx | 4 ++-- .../components/List/__tests__/__snapshots__/List.test.js.snap | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/components/List/List.tsx b/packages/core/src/components/List/List.tsx index 1b69f867c2..9f48d044a0 100644 --- a/packages/core/src/components/List/List.tsx +++ b/packages/core/src/components/List/List.tsx @@ -140,8 +140,8 @@ const List: VibeComponent & { return child; } const id = (child.props as { id: string }).id || `${overrideId}-item-${index}`; - const isFocusableItem = isListItem(childrenRefs.current[index]); - + const currentRef = childrenRefs.current[index]; + const isFocusableItem = currentRef === undefined || currentRef === null || isListItem(currentRef); return React.cloneElement(child, { // @ts-ignore not sure how to deal with ref here ref: ref => (childrenRefs.current[index] = ref), diff --git a/packages/core/src/components/List/__tests__/__snapshots__/List.test.js.snap b/packages/core/src/components/List/__tests__/__snapshots__/List.test.js.snap index 1b318243fd..a9205c8112 100644 --- a/packages/core/src/components/List/__tests__/__snapshots__/List.test.js.snap +++ b/packages/core/src/components/List/__tests__/__snapshots__/List.test.js.snap @@ -29,7 +29,7 @@ exports[`List renders correctly with list items 1`] = ` onFocus={[Function]} onMouseEnter={[Function]} role="option" - tabIndex={-1} + tabIndex={0} > 1