Skip to content

Commit

Permalink
feat(FacetedSearch): Add Typeahead props to QuickSearchInput (#5367)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyanwang authored Jul 3, 2024
1 parent 50d5895 commit 46a18aa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-colts-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-faceted-search': patch
---

feat: Add Typeahead props to QuickSearchInput
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const BasicSearch = ({
quickSearchPlaceholder,
quickSearchFacetsFilter,
quickSearchInputProps,
quickSearchTypeaheadProps,
disclosureProps,
}) => {
const { id, t } = useFacetedSearchContext();
Expand Down Expand Up @@ -129,6 +130,7 @@ const BasicSearch = ({
}}
inputProps={quickSearchInputProps}
minLength={quickSearchMinLength}
typeaheadProps={quickSearchTypeaheadProps}
/>
<div className={styles['tc-basic-search-content']}>
<BadgeFacetedProvider value={badgeFacetedContextValue}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const QuickSearchInput = ({
facetsFilter,
inputProps,
minLength,
typeaheadProps = {},
}) => {
const defaultFacet = useMemo(() => getDefaultFacet(facets), [facets]);
const [opened, setOpened] = useState(false);
Expand Down Expand Up @@ -72,6 +73,7 @@ export const QuickSearchInput = ({
role="searchbox"
className={className}
inputProps={inputProps}
{...typeaheadProps}
/>
);
};
Expand Down
31 changes: 31 additions & 0 deletions packages/faceted-search/stories/facetedSearch.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,34 @@ export const WithQuickSearchFilterCustomizableInputTriggerLength = () => {
</FacetedSearch.Faceted>
);
};

export const WithQuickSearchAsynchronousSuggestions = () => {
const [searching, setSearching] = useState(false);
const [items, setItems] = useState([]);
const [value, setValue] = useState('');
const onChange = (_, { value }) => {
setValue(value);
setSearching(true);
setTimeout(() => {
setItems([
{
title: 'Search in...',
suggestions: ['in Name', 'in Email', 'in Position'].map(column => value + ' ' + column),
},
]);
setSearching(false);
}, 1000);
};

return (
<FacetedSearch.Faceted id="my-faceted-search">
<FacetedSearch.BasicSearch
badgesDefinitions={badgesDefinitions}
callbacks={callbacks}
onSubmit={action('onSubmit')}
quickSearchInputProps={{ value }}
quickSearchTypeaheadProps={{ searching, items, onChange, debounceTimeout: 800 }}
/>
</FacetedSearch.Faceted>
);
};

0 comments on commit 46a18aa

Please sign in to comment.