Remote Search Component
A standalone command menu that queries your server as you type, streaming results back with Turbo.
Preview
Try typing to filter (this demo uses static results; in your app they come from the server):
<%# Basic usage: %>
<%= basecoat_remote_search_tag("/posts/search") %>
<%# With custom turbo frame name: %>
<%= basecoat_remote_search_tag("/posts/search", turbo_frame: "custom_frame") %>
<%# With custom placeholder: %>
<%= basecoat_remote_search_tag("/posts/search", placeholder: "Search posts...") %>
The server side
Your controller responds with a Turbo Stream:
# posts_controller.rb
def search
@posts = Post.where("title LIKE ?", "%#{params[:query]}%")
respond_to do |format|
format.turbo_stream
end
end
And the stream template updates the frame (posts/search.turbo_stream.erb):
<%= turbo_stream.update "_posts_search" do %>
<% @posts.each do |post| %>
<%= link_to post.title, post_path(post), role: "menuitem" %>
<% end %>
<% end %>
Options
| Option | Description | Default |
|---|---|---|
url (required) | The URL to fetch search results from | — |
turbo_frame | Custom frame name | underscored URL, e.g. _posts_search |
placeholder | Placeholder text | "Type a command or search..." |
data_empty | Message when nothing matches | "No results found." |
classes | Extra CSS classes on the component | — |
Requires Stimulus
search_controller.js that debounces input and renders the Turbo Stream response.