From 8131d2ae20173f63c55c5bfb8222a9987c69ce54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 13 Dec 2022 14:51:00 +0100 Subject: [PATCH] fix: call `onValueChange` after filtering the list --- cmdk/src/index.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmdk/src/index.tsx b/cmdk/src/index.tsx index 4506f08..1dfc4d0 100644 --- a/cmdk/src/index.tsx +++ b/cmdk/src/index.tsx @@ -178,11 +178,7 @@ const Command = React.forwardRef((props, forwarded // Filter synchronously before emitting back to children filterItems() sort() - schedule(1, () => { - // Select the first item and emit again - selectFirstItem() - store.emit() - }) + schedule(1, selectFirstItem) } else if (key === 'value') { if (propsRef.current?.value !== undefined) { // If controlled, just call the callback instead of updating state internally @@ -349,7 +345,7 @@ const Command = React.forwardRef((props, forwarded function selectFirstItem() { const item = getValidItems().find((item) => !item.ariaDisabled) const value = item?.getAttribute(VALUE_ATTR) - state.current.value = value || undefined + store.setState('value', value || undefined) } /** Filters the current items. */