kbar icon indicating copy to clipboard operation
kbar copied to clipboard

Create dynamic actions based on user's query input

Open jferrettiboke opened this issue 2 years ago • 2 comments

I'd like to add some actions based on user's query input. Example:

  1. User starts typing in “tesl”.
  2. Kbar renders “tesla.com” and “twitter.com/tesla”. This can be whatever the developer wants to be actually. It just needs creativity.
  3. 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"?

jferrettiboke avatar Jun 25 '22 20:06 jferrettiboke

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

Cygnusfear avatar Jul 17 '22 08:07 Cygnusfear

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.

stale[bot] avatar Sep 15 '22 11:09 stale[bot]

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.

stale[bot] avatar Jan 17 '23 10:01 stale[bot]

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.

stale[bot] avatar May 19 '23 23:05 stale[bot]

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.

stale[bot] avatar Sep 17 '23 11:09 stale[bot]