Skip to content

Conversation

@lorado
Copy link

@lorado lorado commented Feb 3, 2026

πŸ”— Linked issue

Resolves #5974

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Based on the issues described in #5974, following fixes were applied:

  • InputMenu
    • Stop propagation of the "Enter"-key event on the TagsInputInput preventing calling default Reka behaviour, which triggers an internal onAddValue, which isn't connected in any way to Nuxt UI
    • Watch changes in items prop, and in filters are ignored and creation is enabled, trigger to select first item in the dropdown.
  • SelectMenu
    • Similar to InputMenu, SelectMenu had similar issue with focus in Combobox
  • Added additional examples of usage to playground, which covers issues which are fixed now.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

I don't think there is a need to write anything to documentation?

@lorado lorado requested a review from benjamincanac as a code owner February 3, 2026 14:47
@github-actions github-actions bot added the v4 #4488 label Feb 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▢️ Resume reviews
  • πŸ” Trigger review
πŸ“ Walkthrough

Walkthrough

Adds combobox root refs and a post-flush watcher in InputMenu.vue and SelectMenu.vue to call highlightFirstItem() when props.items change while the dropdown is open, ignoreFilter is true, and a createItem exists. Introduces isDropdownOpened state, binds comboboxRootRef, and adds an onInputEnter handler wired to Enter key events to manage create-vs-select behavior. Playground pages (input-menu.vue and select-menu.vue) add parallel "create" flows: searchTermCreate and debounced variants, lazy useFetch calls producing usersCreate with avatar transforms, statusCreate loading flags, and onUserCreate handlers; templates include create-enabled multiple selection inputs/selects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately describes the main changes: fixing unintended item creation and improving focus handling in InputMenu and SelectMenu components.
Description check βœ… Passed The description clearly relates to the changeset, referencing issue #5974 and explaining the fixes applied to InputMenu and SelectMenu with specific technical details.
Linked Issues check βœ… Passed The PR addresses both problems from #5974: (1) tracking dropdown state and highlighting first item when items change; (2) preventing unintended onCreate by stopping Enter key propagation on TagsInputInput and properly handling focus transitions.
Out of Scope Changes check βœ… Passed All changes in InputMenu.vue, SelectMenu.vue and playground files are directly scoped to fixing focus handling and preventing unintended creation as specified in issue #5974.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 3, 2026

npm i https://pkg.pr.new/@nuxt/ui@5986

commit: a4c08df

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

πŸ€– Fix all issues with AI agents
In `@src/runtime/components/SelectMenu.vue`:
- Around line 487-492: The onInputEnter handler currently calls onCreate(e)
whenever there is no highlighted element regardless of whether creation is
enabled; update onInputEnter to first check props.createItem (or an equivalent
create-enabled flag) and only call onCreate(e) when props.createItem is truthy
and comboboxRootRef.value?.highlightedElement is falsy, so pressing Enter won’t
emit a create event when create is disabled; refer to the onInputEnter function,
the onCreate handler, and props.createItem to implement this guard.

@lorado
Copy link
Author

lorado commented Feb 3, 2026

Just realised there was still a not intuitive situation, when focus was in the input-tag, and user moved the focus out of the CheckboxItem, added last failsafe so that on "Enter"-key hit onCreate function still called, but only if there are no items available. If there are any items available, but focus is out of the combobox, I decided to simply bring the focus back to the first option available.

Let me know if there is any need for change.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

πŸ€– Fix all issues with AI agents
In `@src/runtime/components/InputMenu.vue`:
- Around line 503-516: The onInputEnter function currently calls onCreate
unconditionally when there are no items; update it to guard against unwanted
creation by checking the creation flag (e.g., props.createItem or whichever prop
enables creation) before invoking onCreate. In onInputEnter, after the existing
combobox focus and items checks, add a conditional that ensures props.createItem
is truthy (or the appropriate creation-enabled prop) and only then call
onCreate(e); otherwise do nothing (or return). This change should reference
onInputEnter, onCreate, comboboxRootRef, and props.items to locate and fix the
behavior.

@benjamincanac benjamincanac changed the title fix: bug in InputMenu and SelectMenu (#5974) fix(InputMenu/SelectMenu): prevent unintended item creation and improve focus handling Feb 6, 2026
@lorado
Copy link
Author

lorado commented Feb 11, 2026

Figured out, that props.items might be changing even if dropdown isn't displayed. In that case focus should not be triggered.
I added simple variable which is set on open state change, I am not sure if you prefer to use ref variable here.
Let me know if I have to change something

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

πŸ€– Fix all issues with AI agents
In `@src/runtime/components/SelectMenu.vue`:
- Around line 489-506: The onInputEnter handler currently checks props.items to
decide whether to call comboboxRootRef.value?.highlightFirstItem?.(), which
prevents onCreate from being reached when client-side filtering leaves no
visible items; change that guard to use the rendered list length
(filteredItems.value.length) instead of props.items so Enter will create the
visible "create" option when there are no filtered matches; update the same
pattern in InputMenu.vue (the analogous handler) and keep the rest of the logic
(comboboxRootRef, createItem.value, onCreate) unchanged.

Comment on lines +489 to +506
function onInputEnter(e: Event) {
// In case combobox has any focus, skip
if (comboboxRootRef.value?.highlightedElement) {
return
}
// In case we have items but our focus is not within the combobox, just bring the focus back
if ((props.items && props.items.length > 0)) {
comboboxRootRef.value?.highlightFirstItem?.()
e.preventDefault()
e.stopPropagation()
return
}
// In case creation is not allowed skip
if (!createItem.value) {
return
}
onCreate(e)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

🧩 Analysis chain

🏁 Script executed:

fd -t f "SelectMenu.vue" --strip-cwd-prefix

Repository: nuxt/ui

Length of output: 146


🏁 Script executed:

wc -l src/runtime/components/SelectMenu.vue

Repository: nuxt/ui

Length of output: 92


🏁 Script executed:

sed -n '480,520p' src/runtime/components/SelectMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 1357


🏁 Script executed:

sed -n '1,100p' src/runtime/components/SelectMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 4554


🏁 Script executed:

sed -n '100,250p' src/runtime/components/SelectMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 7563


🏁 Script executed:

sed -n '250,400p' src/runtime/components/SelectMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 5910


🏁 Script executed:

sed -n '400,500p' src/runtime/components/SelectMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 3165


🏁 Script executed:

fd -t f "InputMenu.vue" --strip-cwd-prefix

Repository: nuxt/ui

Length of output: 144


🏁 Script executed:

wc -l src/runtime/components/InputMenu.vue

Repository: nuxt/ui

Length of output: 91


🏁 Script executed:

rg -n "onInputEnter" src/runtime/components/InputMenu.vue

Repository: nuxt/ui

Length of output: 189


🏁 Script executed:

sed -n '505,525p' src/runtime/components/InputMenu.vue | cat -n

Repository: nuxt/ui

Length of output: 777


🏁 Script executed:

rg -n "filteredItems" src/runtime/components/InputMenu.vue | head -20

Repository: nuxt/ui

Length of output: 502


🏁 Script executed:

rg -n "ignoreFilter" src/runtime/components/SelectMenu.vue | head -10

Repository: nuxt/ui

Length of output: 206


props.items check prevents onCreate when client-side filtering yields no matches.

When ignoreFilter is false (the default), a user can type a search term that matches nothing in filteredItems, making the create option visible. However, this guard checks props.items (the full, unfiltered list) rather than what's actually rendered. If the raw list has items but filtered results are empty, pressing Enter will call highlightFirstItem() and return instead of reaching onCreate.

This forces the user to press Enter twice (once to highlight the create item, once to select it).

The same pattern exists in InputMenu.vue (line 505).

Use filteredItems.value.length instead:

Proposed fix
-  if ((props.items && props.items.length > 0)) {
+  if (filteredItems.value.length > 0) {
     comboboxRootRef.value?.highlightFirstItem?.()
     e.preventDefault()
     e.stopPropagation()
     return
   }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function onInputEnter(e: Event) {
// In case combobox has any focus, skip
if (comboboxRootRef.value?.highlightedElement) {
return
}
// In case we have items but our focus is not within the combobox, just bring the focus back
if ((props.items && props.items.length > 0)) {
comboboxRootRef.value?.highlightFirstItem?.()
e.preventDefault()
e.stopPropagation()
return
}
// In case creation is not allowed skip
if (!createItem.value) {
return
}
onCreate(e)
}
function onInputEnter(e: Event) {
// In case combobox has any focus, skip
if (comboboxRootRef.value?.highlightedElement) {
return
}
// In case we have items but our focus is not within the combobox, just bring the focus back
if (filteredItems.value.length > 0) {
comboboxRootRef.value?.highlightFirstItem?.()
e.preventDefault()
e.stopPropagation()
return
}
// In case creation is not allowed skip
if (!createItem.value) {
return
}
onCreate(e)
}
πŸ€– Prompt for AI Agents
In `@src/runtime/components/SelectMenu.vue` around lines 489 - 506, The
onInputEnter handler currently checks props.items to decide whether to call
comboboxRootRef.value?.highlightFirstItem?.(), which prevents onCreate from
being reached when client-side filtering leaves no visible items; change that
guard to use the rendered list length (filteredItems.value.length) instead of
props.items so Enter will create the visible "create" option when there are no
filtered matches; update the same pattern in InputMenu.vue (the analogous
handler) and keep the rest of the logic (comboboxRootRef, createItem.value,
onCreate) unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InputMenu as autocomplete (dynamic options + create)

1 participant