Skip to content

Commit

Permalink
fix autocomplete enter and click
Browse files Browse the repository at this point in the history
  • Loading branch information
N.Alivernini committed Sep 28, 2023
1 parent 00e3a77 commit 788a7bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 16 additions & 1 deletion js-packages/search-frontend/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export function Search({
selectionsDispatch={selectionsDispatch}
isColorSearch={isSearchOnInputChange}
setTextBtn={setTextBtn}
isBtnSearch={btnSearch}
/>
);
})}
Expand Down Expand Up @@ -341,7 +342,21 @@ export function Search({
}
} else if (event.key === "Enter") {
event.preventDefault();
setTextBtn(option?.value);
if(btnSearch) {
if (textBtn === "" ) {
selectionsDispatch({
type: "reset-search",
})
} else {
selectionsDispatch({
type: "set-text",
text: option?.value,
textOnchange: option?.value,
});
}
}
option?.value ? setTextBtn(option?.value) : null;

if (span) {
if (isSearchOnInputChange) {
selectionsDispatch({
Expand Down
7 changes: 7 additions & 0 deletions js-packages/search-frontend/src/components/TokenSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type TokenSelectProps = {
isAutoSlected: boolean;
saveSearchQuery?: React.Dispatch<React.SetStateAction<boolean>>;
isColorSearch?: boolean;
isBtnSearch: boolean;
setOpenedDropdown: React.Dispatch<
React.SetStateAction<{
textPosition: number;
Expand All @@ -39,6 +40,7 @@ export function TokenSelect({
selectionsDispatch,
saveSearchQuery,
isColorSearch = true,
isBtnSearch = false,
setTextBtn,
}: TokenSelectProps) {
const isInteractive = span.tokens.length > 0;
Expand Down Expand Up @@ -194,6 +196,11 @@ export function TokenSelect({
key={index}
onClick={() => {
setTextBtn(getTokenLabel(option) || '')
isBtnSearch ? selectionsDispatch({
type: "set-text",
text: option?.value,
textOnchange: option?.value,
}) : null
if (option.tokenType === "AUTOCOMPLETE") {
onSelectText(option);
} else {
Expand Down

0 comments on commit 788a7bf

Please sign in to comment.