Skip to content

Commit fd9f528

Browse files
Export autosuggest parts function (#134)
This PR just export the autosuggest function used to extract the words in the typeahead
1 parent c48d9f5 commit fd9f528

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- New typeahead helper function `getAutosuggestHighlightParts`.
13+
1014
## [3.5.0] - 2025-06-18
1115

1216
### Changed

src/lib/helpers/typeahead.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ const renderHighlightedOptionFunction = (
5555
option: TypeaheadOption,
5656
{ inputValue }: AutocompleteRenderOptionState,
5757
): JSX.Element => {
58-
const finalOption = typeof option === "string" ? option : option.label;
59-
const matches = AutosuggestHighlightMatch(finalOption, inputValue, { insideWords: true });
60-
const parts = AutosuggestHighlightParse(finalOption, matches) as Array<{ text: string; highlight: boolean }>;
58+
const parts = getAutosuggestHighlightParts(option, inputValue);
6159
return (
6260
<li {...props}>
6361
<div>
@@ -71,6 +69,12 @@ const renderHighlightedOptionFunction = (
7169
);
7270
};
7371

72+
const getAutosuggestHighlightParts = (option: TypeaheadOption, inputValue: string): Array<{ text: string; highlight: boolean }> => {
73+
const finalOption = typeof option === "string" ? option : option.label;
74+
const matches = AutosuggestHighlightMatch(finalOption, inputValue, { insideWords: true });
75+
return AutosuggestHighlightParse(finalOption, matches);
76+
};
77+
7478
export {
7579
getSingleAutoCompleteValue,
7680
getMultipleAutoCompleteValue,
@@ -79,4 +83,5 @@ export {
7983
isDisabledGroup,
8084
groupOptions,
8185
renderHighlightedOptionFunction,
86+
getAutosuggestHighlightParts,
8287
};

0 commit comments

Comments
 (0)