fix(InputMenu/SelectMenu): prevent unintended item creation and improve focus handling#5986
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
commit: |
There was a problem hiding this comment.
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.
…ndle focus and items properly
|
Just realised there was still a not intuitive situation, when focus was in the input-tag, and user moved the focus out of the Let me know if there is any need for change. |
There was a problem hiding this comment.
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.
…putMenu` and `SelectMenu`
InputMenu and SelectMenu (#5974)|
Figured out, that props.items might be changing even if dropdown isn't displayed. In that case focus should not be triggered. |
There was a problem hiding this comment.
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.
howwohmm
left a comment
There was a problem hiding this comment.
read through the full diff — the fix direction is right but there's a functional issue in multiple mode.
the .stop.prevent modifier on the TagsInput enter handler (line ~167 in the diff) prevents default before onInputEnter runs. so even when comboboxRootRef.value?.highlightedElement exists and the handler returns early (intending to let reka-ui's native selection behavior through), the event has already been stopped and prevented. this means Enter-to-select a highlighted item won't work in multiple mode.
contrast with the single-mode input which has no .stop.prevent modifier on the template — it handles e.preventDefault() and e.stopPropagation() conditionally inside the function. the multiple-mode handler should do the same:
<!-- instead of -->
@keydown.enter.stop.prevent="onInputEnter"
<!-- use -->
@keydown.enter="onInputEnter"and let the function call e.preventDefault() / e.stopPropagation() only when it actually handles the event (the createItem path).
also minor: if ((props.items && props.items.length > 0)) has unnecessary double parens — single parens match the rest of the codebase.
the watch on props.items with highlightFirstItem() for the ignoreFilter case is a good approach though.
# Conflicts: # src/runtime/components/InputMenu.vue # src/runtime/components/SelectMenu.vue
|
hi @howwohmm, thank you for your time! I would like to disagree with you. Enter event on hovered elements is processed before input, and RekaUI acutally kills these events in their logic. You can check it in ListboxRoot which is used in Combobox. In case of multiple, Single case uses regular input, so there is no need to shut the event down. I am updating code to keep this PR up to date, as I require this fix in my project. |
|
Ok, I merged to most recent v4 branch, adjusted code slightly ( Everything seems to work. If you guys still need some changes - let me know |
🔗 Linked issue
Resolves #5974
❓ Type of change
📚 Description
Based on the issues described in #5974, following fixes were applied:
TagsInputInputpreventing calling default Reka behaviour, which triggers an internalonAddValue, which isn't connected in any way to Nuxt UIitemsprop, and in filters are ignored and creation is enabled, trigger to select first item in the dropdown.📝 Checklist
I don't think there is a need to write anything to documentation?