Skip to content

Commit 6ad8a86

Browse files
authored
fix: call onValueChange after filtering the list (#70)
1 parent 605ae13 commit 6ad8a86

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

cmdk/src/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
178178
// Filter synchronously before emitting back to children
179179
filterItems()
180180
sort()
181-
schedule(1, () => {
182-
// Select the first item and emit again
183-
selectFirstItem()
184-
store.emit()
185-
})
181+
schedule(1, selectFirstItem)
186182
} else if (key === 'value') {
187183
if (propsRef.current?.value !== undefined) {
188184
// If controlled, just call the callback instead of updating state internally
@@ -349,7 +345,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
349345
function selectFirstItem() {
350346
const item = getValidItems().find((item) => !item.ariaDisabled)
351347
const value = item?.getAttribute(VALUE_ATTR)
352-
state.current.value = value || undefined
348+
store.setState('value', value || undefined)
353349
}
354350

355351
/** Filters the current items. */

0 commit comments

Comments
 (0)