Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call onValueChange after filtering the list #70

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't need to emit again now because selectFirstItem calls into setState with the new value and that causes a new emit already

})
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