feat: Add o-autocomplete configurable highlighting #1658
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.
Describe your changes
This PR applies changes so that custom
suggestionTemplate
callbacks provided as an option when instantiating an instance ofoAutocomplete
will now receive two additional arguments:highlightSuggestion()
— as declared hereisMatchHighlighted
— a boolean to determine whether matching or non-matching characters should be highlighted, which in turn is passed as an argument to thehighlightSuggestion()
function within a customsuggestionTemplate()
function (that has been passed as an option when instantiating an instance ofoAutocomplete
) or within the nativesuggestionTemplate()
functionIn the scenario of a custom
suggestionTemplate
, I'm not sure if it's a code smell or anti-pattern that theisMatchHighlighted
value is passed at instantiation and then reappears via thesuggestionTemplate()
callback where there is technically no compulsion to use that value as intended, i.e. givensuggestionTemplate()
is custom, theisMatchHighlighted
value could be declared within that function, making its presence as a parameter redundant. However, it seems far neater to declare up-front at time of instantiation all the configuration that dictates how you would like the component to behave.I would also a prefer a better variable name than
isMatchHighlighted
— set totrue
it makes sense, though when set tofalse
it implies that it will simply not highlight matched characters (and by inference, that it will highlight nothing at all) rather than expressing that it will highlight the characters that are not a match. Naming is hard…Scenario 1
Custom
suggestionTemplate
with highlights applied to options where it matches querysuggestionTemplate
option is providedisMatchHighlighted
option is provided with a value oftrue
Scenario 2
Custom
suggestionTemplate
with highlights applied to options where it does NOT match querysuggestionTemplate
option is providedisMatchHighlighted
option is NOT provided (or is provided with a value offalse
)OR
Scenario 3
o-autocomplete native
suggestionTemplate
with highlights applied to options where it matches querysuggestionTemplate
option is NOT providedisMatchHighlighted
option is provided with a value oftrue
Scenario 4
o-autocomplete native
suggestionTemplate
with highlights applied to options where it does NOT match querysuggestionTemplate
option is NOT providedisMatchHighlighted
option is NOT provided (or is provided with a value offalse
)OR
Issue ticket number and link
Link to Figma designs
Checklist before requesting a review
percy
label for o-[COMPONENT] orchromatic
label for o3-[COMPONENT] on my PR before merging and after review. Find more details in CONTRIBUTING.md