diff --git a/packages/sanity/src/core/components/commandList/CommandList.tsx b/packages/sanity/src/core/components/commandList/CommandList.tsx index 372803dcbdc0..ce987c3ca1c8 100644 --- a/packages/sanity/src/core/components/commandList/CommandList.tsx +++ b/packages/sanity/src/core/components/commandList/CommandList.tsx @@ -463,13 +463,29 @@ export const CommandList = forwardRef(funct setActiveIndex({index}) enableChildContainerPointerEvents(true) }, + selectCurrent() { + const childElements = Array.from(childContainerElement?.children || []) as HTMLElement[] + const currentElement = childElements.find( + (el) => + Number(el.dataset.index) === + itemIndices.findIndex((i) => i.activeIndex === activeIndexRef.current), + ) + if (currentElement) { + const clickableElement = currentElement?.querySelector( + LIST_ITEM_INTERACTIVE_SELECTOR, + ) + clickableElement?.click() + } + }, } }, [ + childContainerElement?.children, enableChildContainerPointerEvents, focusInputElement, focusListElement, handleGetTopIndex, + itemIndices, setActiveIndex, ], ) diff --git a/packages/sanity/src/core/components/commandList/types.ts b/packages/sanity/src/core/components/commandList/types.ts index 26867fc6a500..5c29926ea342 100644 --- a/packages/sanity/src/core/components/commandList/types.ts +++ b/packages/sanity/src/core/components/commandList/types.ts @@ -34,6 +34,7 @@ export interface CommandListHandle { focusListElement: () => void getTopIndex: () => number scrollToIndex: (index: number) => void + selectCurrent: () => void } /** @internal */