diff --git a/resources/scripts/components/admin/nodes/LocationSelect.tsx b/resources/scripts/components/admin/nodes/LocationSelect.tsx index 219a99b70..b7974dda1 100644 --- a/resources/scripts/components/admin/nodes/LocationSelect.tsx +++ b/resources/scripts/components/admin/nodes/LocationSelect.tsx @@ -27,27 +27,21 @@ export default ({ defaultLocation }: { defaultLocation: Location }) => { setExpanded(true); }; - const onBlur = () => { - // setInputText(location.short); - // setExpanded(false); - }; - const search = debounce((query: string) => { if (!expanded) { return; } - if (query === '') { + if (query === '' || query.length < 2) { setLocations([]); return; } setLoading(true); searchLocations({ short: query }).then((locations) => { - console.log(locations); setLocations(locations); }).then(() => setLoading(false)); - }, 200); + }, 250); const selectLocation = (location: Location) => { setLocation(location); @@ -58,13 +52,29 @@ export default ({ defaultLocation }: { defaultLocation: Location }) => { setExpanded(false); }, [ location ]); + useEffect(() => { + const handler = (e: KeyboardEvent) => { + if (e.key !== 'Escape') { + return; + } + + setInputText(location.short); + setExpanded(false); + }; + + window.addEventListener('keydown', handler); + return () => { + window.removeEventListener('keydown', handler); + }; + }, [ expanded ]); + return (
Please type 2 or more characters.
+