Allow filtering the HTML of Autosuggest items. #2146
Merged
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.
Description of the Change
Applies a
epAutosuggestItemHTMLFilter()
function to autosuggest items to allow filtering the HTML of autosuggest results.Alternate Designs
In this implementation the filter callback only receives the option object as the second argument, and the option index as the third argument. These can be used to reconstruct the original HTML, or a variation of it, if desired. This means that a custom filter would need to implement any required escaping, as well as highlighting.
An alternative approach could be to also pass the pre-processed escaped text and highlighted results text as arguments to the callback.
The appropriate approach would depend on how much hand holding we want to do.
Benefits
Developers can provide their own HTML for autosuggest result items.
Possible Drawbacks
The potential for autosuggest results to break if future changes are made to the HTML of results that are not reflected in the HTML that may have been applied by a filter.
Verification Process
npm run build
.window.epAutosuggestItemHTMLFilter()
JavaScript function that returns some HTML.epAutosuggestItemHTMLFilter()
function.Checklist:
Applicable Issues
#2143
#2128
Changelog Entry
Added the ability to filter the HTML of autosuggest results by defining a
window.epAutosuggestItemHTMLFilter()
function in JavaScript.