[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX][UX] Autocomplete: Refocus input when no autocomplete results are found

"MAGENE Sem Joel \(@Jomagene\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68cb0dbe60245_2cdebe82667e@gitlab-sidekiq-low-urgency-cpu-bound-v2-757fcbb555-bj4bx.mail>

MAGENE Sem Joel pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
433b885d by MAGENE Sem Joel at 2025-09-17T19:28:59+00:00
[BP][FIX][UX] Autocomplete: Refocus input when no autocomplete results are found
---
* [FIX][UX] Autocomplete: Refocus input when no autocomplete results are found
---
* [FIX][UX] Autocomplete: Refocus input when no autocomplete results are found

See merge request tikiwiki/tiki!8521

(cherry picked from commit ac6aca227a522325632092d34e3b079097a340c6)

See merge request tikiwiki/tiki!8597

- - - - -


1 changed file:

- src/js/vue-widgets/element-plus-ui/src/components/Autocomplete/Autocomplete.vue


Changes:

=====================================
src/js/vue-widgets/element-plus-ui/src/components/Autocomplete/Autocomplete.vue
=====================================
@@ -7,10 +7,30 @@ const props = defineProps(['value', 'remoteSourceUrl', 'sourceList', 'emitCustom
 
 const valueKey = props.valueKey || 'value';
 const placeholder = props.placeholder || TEXT.INPUT_PLACEHOLDER;
+const shouldRefocusOnBlur = ref(false);
 
 const modelValue = ref(props.value);
+const autocompleteRef = ref(null);
 
-const handleFetchSuggestions = (query, callback) => fetchSuggestions(query, callback, props.remoteSourceUrl, (props.sourceList ? JSON.parse(props.sourceList): []));
+const handleFetchSuggestions = (query, callback) => {
+    const wrappedCallback = (results) => {
+        callback(results);
+
+        if (!results || results.length === 0) {
+             // If there are no results, set a flag indicating that the next blur event is likely programmatic and should be counteracted by a refocus.
+            shouldRefocusOnBlur.value = true;
+        }
+    };
+    fetchSuggestions(query, wrappedCallback, props.remoteSourceUrl, (props.sourceList ? JSON.parse(props.sourceList): []));
+}
+
+const handleBlur = () => {
+    // Refocuses the input if the blur was triggered programmatically by a "no results" event.
+    if (shouldRefocusOnBlur.value) {
+        autocompleteRef.value?.inputRef?.focus();
+        shouldRefocusOnBlur.value = false;
+    }
+};
 
 const handleSelect = (value) => {
     props.emitCustomEvent('select', value);
@@ -46,6 +66,7 @@ export const DATA_TEST_ID = {
 <template>
     <ConfigWrapper :language="language">
         <el-autocomplete
+            ref="autocompleteRef"
             v-model="modelValue"
             :debounce="500"
             :trigger-on-focus="false"
@@ -56,6 +77,7 @@ export const DATA_TEST_ID = {
             @select="handleSelect"
             @input="handleInput"
             @keyup.enter="handlePressEnter"
+            @blur="handleBlur"
             clearable
             :teleported="false"
         >



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/433b885d35097b55965c3526f0ca7b5854079af1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/433b885d35097b55965c3526f0ca7b5854079af1
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.