wire-elements / spotlight

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
MIT License
927 stars 72 forks source link

Feature Request: Option to trigger search on load #48

Closed seabasss closed 3 years ago

seabasss commented 3 years ago

Been sending a lot of feedback, but I really love this package :)

It would be cool if you could add an option to trigger the search automatically if wanted. So in addition to the For which team do you want to create a user? placeholder it would also perform a search and show all available Teams without you having to type anything. Not as default, but I could see it handy when there are only a few options available and you want to show the user all of them right away.

Maybe there is a more elegant solution, but you get the point:

->add(SpotlightCommandDependency::make('team')->setPlaceholder('For which team do you want to create a user?')->triggerSearch(true))

Even one step further, in addition to true or '' for all results, you could add a search term triggerSearch('Seabass') or triggerSearch($user->personalTeam()->name) and that would populate as your starting point. In this case show my team as auto-selected.

Just an idea :)

PhiloNL commented 3 years ago

Thanks for the feedback :) To verify, you already want to show a selection of teams to be displayed below the placeholder (when the input is empty)?

Placeholder: For which team do you want to create a user?

Results:
- Team 1
- Team 2
- Team 3

And when you start typing it will search:

Input query: Team 3
- Team 3
seabasss commented 3 years ago

Exactly! But again, I don’t think it should be the default behavior and the query should wait until you start typing as default, but would be really cool to allow both ways.

One suggestion:

->triggerSearch(false) or not added gives you the behavior it has currently with only the placeholder and query when typing.

->triggerSearch(true) gives you all Teams without any typing on empty (your first example)

->triggerSearch(’Team 3’) gives you your second example with ’Team 3’ pre-populated in the search box with the query executed.

There may be a more descriptive word than triggerSearch and maybe the setting would be applied in a different way, but just throwing out the idea.