Add searchQuery() and autoSearch() methods to Combobox component#4
Merged
Merged
Conversation
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add defaultSearchQuery method and searchQuery trigger
Add defaultSearchQuery() and searchQuery() methods to Combobox component
Oct 17, 2025
Contributor
|
@copilot Lets delete the defaultSearchQuery() and $defaultSearchQuery variable. instead use the searchQuery() function and add a "autoSearch" method instead. instead of automatically searching when we pass a value to searchQuery() we use the "autoSearch" to indicate that behaviour. |
…h() pattern Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
Contributor
Author
Done! I've refactored the implementation as requested: Changes made (commit 72c9c38):
New API: // Set a search query without auto-search
Combobox::make('product')
->searchable()
->searchQuery('electronics')
// Set a search query with auto-search
Combobox::make('product')
->searchable()
->getSearchResultsUsing(fn($search) => Product::search($search))
->searchQuery('electronics')
->autoSearch()
// Conditional auto-search
Combobox::make('product')
->searchQuery($categoryName)
->autoSearch(filled($categoryName))The separation provides better control - |
Copilot
AI
changed the title
Add defaultSearchQuery() and searchQuery() methods to Combobox component
Add searchQuery() and autoSearch() methods to Combobox component
Oct 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds two new methods to the Combobox component that enable setting search queries and controlling automatic search triggering on component initialization.
Problem
Previously, there was no way to:
This limitation made it difficult to pre-filter options based on context, such as showing products from a specific category or filtering items based on user permissions.
Solution
Added two new fluent methods to the
Comboboxclass:1.
searchQuery(string | Closure | null $query)Sets the search query value in the search input without triggering a search by default. This is useful for setting initial values in the search field.
2.
autoSearch(bool | Closure $condition = true)Controls whether to automatically trigger a search when the component boots. When combined with
searchQuery(), this enables pre-filtering options based on context.You can also conditionally enable auto-search:
Implementation Details
Backend (PHP)
searchQuery()method to set the search query valueautoSearch()method to control automatic search behaviorClosurefor dynamic valuesFrontend (JavaScript)
Comboboxconstructor to acceptsearchQueryandautoSearchparametersperformInitialSearch()method that:getSearchResultsUsingor local filteringautoSearchis trueAssets
Use Cases
->searchQuery($categoryName)->autoSearch()to show products from a specific category->searchQuery(auth()->user()->department)->autoSearch()to filter items by user context->searchQuery($this->related_field)->autoSearch()to pre-filter based on another field's value->searchQuery('electronics')to set initial search text without triggering searchDocumentation
Added comprehensive usage examples and explanations to the README.md showing how to use both methods and their practical applications.
Testing
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.