@@ -81,6 +81,7 @@ const props = defineProps<{
8181 optionsListId? : string ;
8282 debug? : boolean ;
8383 required? : boolean ;
84+ showCreateTextOnNewItem? : boolean ;
8485}>();
8586
8687const emit = defineEmits <{
@@ -106,6 +107,7 @@ const selectedOptionTitle = ref<string | null>(null);
106107const shouldDisplayOptions = ref (false );
107108const highlightedOptionKey = ref <string | symbol | null >(null );
108109const shouldShowCreateOption = ref (false );
110+ const shouldShowCreateTextOnNewItem = computed (() => props .showCreateTextOnNewItem ?? true );
109111
110112const effectivePrependOptions = computed (() => props .prependOptions ?? []);
111113const effectiveAppendOptions = computed (() => props .appendOptions ?? []);
@@ -190,7 +192,9 @@ const effectiveOptions = computed(() => {
190192 if (! hasExactMatch ) {
191193 options .push ({
192194 key: CreateSymbol ,
193- title: ' Create <strong>' + searchText .value .trim () + ' </strong>...'
195+ title: shouldShowCreateTextOnNewItem .value
196+ ? ' Create <strong>' + searchText .value .trim () + ' </strong>...'
197+ : searchText .value .trim ()
194198 });
195199 }
196200 }
@@ -303,6 +307,7 @@ function handleKeyDown(e: KeyboardEvent) {
303307 if (e .key == ' Escape' ) {
304308 e .stopPropagation ();
305309 (e .target as HTMLInputElement ).blur ();
310+ focusNextInput ();
306311 return ;
307312 }
308313
@@ -496,6 +501,7 @@ function selectOption(option: OptionDescriptor) {
496501 }
497502
498503 searchField .value ?.blur ();
504+ focusNextInput ();
499505}
500506
501507function handleValueChanged() {
@@ -515,6 +521,21 @@ function handleValueChanged() {
515521function addRemoteOption(option : T ) {
516522 loadedOptions .value .unshift (option );
517523}
524+
525+ function focusNextInput() {
526+ let parent = el .value ?.parentElement ;
527+ while (parent && parent .tagName !== ' FORM' && parent .tagName !== ' BODY' ) {
528+ parent = parent .parentElement ;
529+ }
530+ if (! parent ) return ;
531+
532+ const allFocusableElements = parent .querySelectorAll (' input, button, textarea, select, [tabindex]:not([tabindex="-1"])' );
533+ if (! allFocusableElements ) return ;
534+
535+ const currentInputIndex = Array .from (allFocusableElements ).findIndex (el => el === searchField .value );
536+ const nextInput = allFocusableElements [currentInputIndex + 1 ] as HTMLElement ;
537+ if (nextInput ) setTimeout (() => nextInput .focus (), 0 );
538+ }
518539 </script >
519540
520541<style lang="scss">
0 commit comments