Skip to content

Commit

Permalink
[ONC-65] Fix search auto suggest (#7972)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptype authored Mar 28, 2024
1 parent f79e98b commit 361d87e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/web/src/components/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SearchBar extends Component {
super(props)
this.state = {
open: false,
focused: false,
// State variable set to true when an item has been selected.
selected: false,
value: '',
Expand Down Expand Up @@ -129,7 +130,7 @@ class SearchBar extends Component {
}

onFocus = () => {
this.setState({ shouldDismissTagPopup: false })
this.setState({ shouldDismissTagPopup: false, focused: true })
this.searchBarRef.current
.getElementsByClassName('ant-select-selection-search')[0]
.classList.add('expanded')
Expand Down Expand Up @@ -163,7 +164,7 @@ class SearchBar extends Component {
.getElementsByClassName('ant-select-selection-search')[0]
.classList.remove('expanded')
}
this.setState({ open: false })
this.setState({ open: false, focused: false })
}
}

Expand Down Expand Up @@ -222,6 +223,14 @@ class SearchBar extends Component {
!isEqual(nextProps.dataSource, this.props.dataSource) &&
nextProps.resultsCount > 0
) {
if (
!nextState.selected &&
!nextState.valueFromParent &&
// Only open the suggestions if the search bar is focused
nextState.focused
) {
this.setState({ open: true })
}
if (nextProps.status === Status.SUCCESS) {
return true
}
Expand All @@ -233,6 +242,14 @@ class SearchBar extends Component {
nextProps.resultsCount === 0 &&
this.state.value !== ''
) {
if (
!nextState.selected &&
!nextState.valueFromParent &&
// Only open the suggestions if the search bar is focused
nextState.focused
) {
this.setState({ open: true })
}
return false
}
// Close the dropdown if we're searching for '' (deleted text in search).
Expand Down

0 comments on commit 361d87e

Please sign in to comment.