kbar
kbar copied to clipboard
Create dynamic actions based on user's query input
I'd like to add some actions based on user's query input. Example:
- User starts typing in “tesl”.
- Kbar renders “tesla.com” and “twitter.com/tesla”. This can be whatever the developer wants to be actually. It just needs creativity.
- User selects the appropriate one.
Spotlight has support for this. GitHub as well. Having the primitives that allow us to build something similar would be great.
My questions are:
- Is there any way to access what the user is typing in?
- Can we create actions after users type something in? Or, can we only create actions before users start typing something in?
- Can we edit the action name dynamically so that we can add fallbacks like "Search for [query] on the web"?
I'm digging around in the source, maybe this helps as a starting point:
- You can access the current searchQuery and your actions with the useKBar hook:
const { search, actions } = useKBar(state => ({
search: state.searchQuery,
actions: state.actions
}))
- The docs describe a
useRegisterActions
hook, which can be used to dynamically add actions
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.