From 7f4c22f13003ba204ae74aa70fa27e01608b8905 Mon Sep 17 00:00:00 2001 From: ddifiore <89548500+ddifiore@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:06:23 -0400 Subject: [PATCH] Updating the escape button behavior --- ui/component/wunderbarSuggestions/view.jsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ui/component/wunderbarSuggestions/view.jsx b/ui/component/wunderbarSuggestions/view.jsx index 735adc663..fd778cbe5 100644 --- a/ui/component/wunderbarSuggestions/view.jsx +++ b/ui/component/wunderbarSuggestions/view.jsx @@ -228,20 +228,26 @@ export default function WunderBarSuggestions(props: Props) { React.useEffect(() => { function handleKeyDown(event) { const { ctrlKey, metaKey, keyCode } = event; + + if (!inputRef.current) { + return; + } if (keyCode === K_KEY_CODE && ctrlKey) { inputRef.current.focus(); inputRef.current.select(); return; } - - if (!inputRef.current) { - return; - } if (inputRef.current === document.activeElement && keyCode === ESC_KEY_CODE) { - inputRef.current.value = ""; - inputRef.current.focus(); + // If the user presses escape and the text has already been cleared then blur the widget + if (inputRef.current.value === '') { + inputRef.current.blur(); + } else { + // Remove the current text + inputRef.current.value = ''; + inputRef.current.focus(); + } } // @if TARGET='app'