fix(InputMenu): stop adding new chip in ui in case not create mode - #6776
fix(InputMenu): stop adding new chip in ui in case not create mode#6776al1maher wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthrough
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/runtime/components/InputMenu.vue (1)
551-560: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression test for disabled item creation.
Please cover Enter with
multiple: true, a non-empty search term, andcreateItem: false, asserting that neither a chip nor anupdate:modelValueevent is produced. Also verify that enabledcreateItembehavior remains unchanged.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/runtime/components/InputMenu.vue` around lines 551 - 560, Add regression coverage for onTagInputKeydown in the InputMenu tests: with multiple enabled, a non-empty search term, and createItem false, pressing Enter must produce neither a chip nor an update:modelValue event. Add a corresponding createItem true case to confirm Enter still creates the tag and emits the expected model update.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/runtime/components/InputMenu.vue`:
- Around line 551-560: Add regression coverage for onTagInputKeydown in the
InputMenu tests: with multiple enabled, a non-empty search term, and createItem
false, pressing Enter must produce neither a chip nor an update:modelValue
event. Add a corresponding createItem true case to confirm Enter still creates
the tag and emits the expected model update.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7fa69814-cbac-4d32-800e-d2a259aeb798
📒 Files selected for processing (1)
src/runtime/components/InputMenu.vue
commit: |
| function onTagInputKeydown(e: KeyboardEvent) { | ||
| if (e.key !== 'Enter') return | ||
|
|
||
| // reka-ui's TagsInputRoot adds the raw search text as a tag on Enter regardless of | ||
| // whether it matches a real item or createItem is enabled. Block that so | ||
| // we never render a chip that isn't reflected in modelValue. | ||
| if (!props.createItem) { | ||
| e.preventDefault() | ||
| } | ||
| } |
There was a problem hiding this comment.
Thanks @al1maher! I don't think createItem is the right check though, the chip is still there with createItem: true and the menu closed. And preventing every Enter breaks form submission inside a UForm.
I think I would use searchTerm instead:
| function onTagInputKeydown(e: KeyboardEvent) { | |
| if (e.key !== 'Enter') return | |
| // reka-ui's TagsInputRoot adds the raw search text as a tag on Enter regardless of | |
| // whether it matches a real item or createItem is enabled. Block that so | |
| // we never render a chip that isn't reflected in modelValue. | |
| if (!props.createItem) { | |
| e.preventDefault() | |
| } | |
| } | |
| function onTagsInputKeydown(event: KeyboardEvent) { | |
| if (event.isComposing || !searchTerm.value) { | |
| return | |
| } | |
| event.preventDefault() | |
| } |
What do you think?
There was a problem hiding this comment.
I think your approach is more correct, I made it that way as I was focusing on not breaking the create functionality but I think your solution is more robust
🔗 Linked issue
Resolves #6760
❓ Type of change
📚 Description
Stop creating a new chip in UI when the user searches and press Enter
📝 Checklist