-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
feat: add onStateChange
callback to Command component
#972
Conversation
…e notifications - Introduced `onStateChange` prop in `CommandRootProps` to allow external handling of internal state changes. - Updated `CommandRootState` to manage state updates more efficiently, including debouncing state change notifications. - Enhanced `Command` component to pass `onStateChange` prop to the root state. - Updated API documentation to reflect the new `onStateChange` functionality.
🦋 Changeset detectedLatest commit: cadca87 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Awesome work @max-got! I intentionally left this part out of the move over to Bits UI as I wanted to spend time thinking about how best to enable the user to manage that state, given if we have an Where this starts to get messy is when we do provide the The user can't just do In the meantime though, we can merge this in as it wouldn't be a breaking change to add those in the future. |
It seems there was a regression introduced though, demonstrated by the following video where the highlight doesn't restore to the top of the list: CleanShot.2024-12-04.at.11.04.42.mp4 |
- Removed unnecessary flags for first mount and updating state. - Introduced a new scheduling mechanism for state updates to improve efficiency. - Simplified the emit logic by consolidating it into a single scheduling function. - Enhanced the handling of item selection during filtering and sorting operations. - Updated related methods to ensure consistent state updates without redundant emissions.
I've changed the logic a quite a bit. tests for the combobox would be awesome tho. for now i am flying blind, but the issue should be fixed. |
Agreed 😃 , it's on my list of things to do
Thank you, I'll give it a check soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
As i was trying to reimplement Multiple Selector for Origin UI Svelte i didn't found a way to access the current filtered items for select-{46|47}. See Original "Multiselect, Multiselect with placeholder and clear."
Initially i wanted to give the user something like
useCommandState
, but that felt wrong. But maybe there is a better solution. I just wanted to kickstart something like this! Feel free to close this, if you think that is the wrong approach!This PR introduces a new
onStateChange
callback to the Command component, allowing consumers to track and react to internal state changes.Changes
onStateChange
prop toCommandRootProps
that receives a readonly snapshot of the component's internal stateonStateChange
functionalityImplementation Details
The state management system now:
afterTick
to ensure all related updates are processed before notifyingExample Usage
Testing
No test files found, tho i tested locally: