Skip to content

Commit

Permalink
ON-33060 # Using inputOption.value + moved useEffect down
Browse files Browse the repository at this point in the history
  • Loading branch information
josh215 committed Jul 18, 2023
1 parent 598c820 commit 5b0545b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/components/renderer/AutocompleteDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function AutocompleteDropdown<T>({
(option) => option.label.toLowerCase() === lowerCase,
)
if (option) {
if (!value) {
if (!inputOption.value) {
console.log('Setting value after blurring away from autocomplete')
onSelectOption(option)
}
Expand All @@ -113,7 +113,6 @@ function AutocompleteDropdown<T>({
onSelectOption,
options,
setIsDirty,
value,
],
)

Expand Down Expand Up @@ -238,6 +237,14 @@ function AutocompleteDropdown<T>({
}
}, [isOpen, label, onSearch, searchDebounceMs, searchMinCharacters])

React.useEffect(() => {
//If there is no value set, we want to clear the label
//This is to satisfy lookups that return undefined.
if (!value) {
onChangeLabel('')
}
}, [onChangeLabel, value])

const isShowingLoading = isFetchingOptions || !!isLoading
const isShowingValid = !isShowingLoading && value !== undefined
const isShowingError = !isShowingLoading && !!hasError
Expand Down
5 changes: 0 additions & 5 deletions src/form-elements/FormElementAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ const AutocompleteFilter = React.memo(function AutocompleteFilter({
setLabel(option.label)
}

//If there is no value set, we want to clear the label
//This is to satisfy lookups that return undefined.
if (!value && label) {
setLabel('')
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [element.options, value])

Expand Down

0 comments on commit 5b0545b

Please sign in to comment.