Skip to content

Commit

Permalink
fix: call onValueChange after filtering the list (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 16, 2022
1 parent 605ae13 commit 6ad8a86
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((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
Expand Down Expand Up @@ -349,7 +345,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((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. */
Expand Down

1 comment on commit 6ad8a86

@vercel
Copy link

@vercel vercel bot commented on 6ad8a86 Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cmdk-website – ./

cmdk.vercel.app
cmdk-website-paco.vercel.app
cmdk.paco.me
cmdk-website-git-main-paco.vercel.app

Please sign in to comment.