-
Notifications
You must be signed in to change notification settings - Fork 6
fix: allow form submission with single Enter press in ComboBox #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@cube-dev/ui-kit": patch | ||
| --- | ||
|
|
||
| Fix ComboBox with `allowsCustomValue` to allow form submission with single Enter press when typing custom values that don't match any items. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| description: When user asked to add a changeset | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| Place the changeset to `/.changeset` folder. | ||
| Use `patch` version for small fixed (even with breaking changes if they are minor). Use `minor` version for bigger features and noticeable breaking changes. | ||
| Use diff of the working tree to analyze changes. If it's empty then use the diff with the `main` branch. | ||
| Try to make the changeset concise. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| description: When commiting the changes | ||
| alwaysApply: false | ||
| --- | ||
|
|
||
| Use Conventional Commits convention. | ||
| If changes described in changesets are isolated (For example in a single component) then use syntax with `()` like `fix(ComboBox): what exactly is fixed` and so on. | ||
| The name of the commit should be as short as possible. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -605,15 +605,21 @@ function useComboBoxKeyboard({ | |
|
|
||
| // If no results, handle empty input or custom values | ||
| if (!hasResults) { | ||
| e.preventDefault(); | ||
|
|
||
| if (allowsCustomValue) { | ||
| const value = effectiveInputValue; | ||
| const value = effectiveInputValue.trim(); | ||
|
|
||
| // Commit the custom value | ||
| onSelectionChange( | ||
| (value as unknown as Key) ?? (null as unknown as Key), | ||
| ); | ||
|
|
||
| // If popover is closed and we have a value, allow Enter to propagate for form submission | ||
| // If popover is open OR value is empty, prevent default to avoid premature submission | ||
| if (isPopoverOpen || !value) { | ||
| e.preventDefault(); | ||
| } | ||
| } else { | ||
| e.preventDefault(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Popover: Enter Submits Form Without Focus.When the popover is open with matching results but no item is focused, pressing Enter doesn't prevent default, causing premature form submission. The Enter handler falls through all conditions without calling |
||
| onSelectionChange(null); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Normalize empty custom input to
null.When
allowsCustomValueis true and the user enters only whitespace then presses Enter,onSelectionChangeis called with an empty string instead ofnull. The??operator on line 613 doesn't convert empty strings tonull(onlynull/undefined), soonSelectionChange("")is called. This is inconsistent with how empty values are handled elsewhere in the component (e.g., lines 631-634), wherenullis used to represent "no selection". The code should check if the trimmed value is empty and callonSelectionChange(null)instead.