Skip to content

Commit

Permalink
DBC22-1948: fixed onBlur error
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrel-oxd committed Apr 18, 2024
1 parent 8f3a96f commit 16206aa
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/frontend/src/Components/map/LocationSearch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// React
import React, { useState } from 'react';
import { useDispatch } from 'react-redux'
import { useDispatch } from 'react-redux';

// react-bootstrap-typeahead
import { AsyncTypeahead } from 'react-bootstrap-typeahead';
Expand All @@ -21,12 +21,12 @@ export default function LocationSearch(props) {
const [isSearching, setSearching] = useState(false);
const [options, setLocationOptions] = useState([]);

const setSelectedLocation = (payload) => {
window.document.activeElement.blur(); // De-focus textbox
const setSelectedLocation = payload => {
window.document.activeElement.blur(); // De-focus textbox
dispatch(action(payload));
}
};

const loadLocationOptions = (locationInput) => {
const loadLocationOptions = locationInput => {
setSearching(true);
getLocations(locationInput).then(locationsData => {
setLocationOptions(
Expand All @@ -39,7 +39,7 @@ export default function LocationSearch(props) {
);
setSearching(false);
});
}
};

// Rendering
return (
Expand All @@ -53,8 +53,16 @@ export default function LocationSearch(props) {
minLength={3}
onChange={setSelectedLocation}
onSearch={loadLocationOptions}
onBlur={()=>{
trackEvent('blur', 'route search', 'location search', location[0].properties.fullAddress)}}
onBlur={() => {
if (location[0]) {
trackEvent(
'blur',
'route search',
'location search',
location[0].properties.fullAddress,
);
}
}}
options={options}
placeholder={placeholder}
highlightOnlyResult={true}
Expand Down

0 comments on commit 16206aa

Please sign in to comment.