Skip to content
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

Fix: Only preventDefault if there is a highlighted item #1185

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

RedPhoenixQ
Copy link

Hello, I'm relatively new to PR's and am glad to explain or fix anything that would be needed.

In the listbox input the key input handler called preventDefault unnecessarily. The comment above on line 364 says that pressing enter with a highlighted item should select it, which should mean that when there is no highlighted item nothing should happen.

The current behaviour prevents the input from being used as expected in forms when pressing Enter, instead first closing the list and on the second press of Enter submitting the form.

My current use case is a searchbox with result showing up in the listbox content as you type using bits-ui, which uses this listbox. This is placed in a form that should include the search input as typed when pressing enter, but currently it requires pressing it twice.

If there is no highlighted item `preventDefault` should not be called.
The current behaviour prevents the input from being used as expected
in forms when pressing `Enter`, instead first closing the list and
on the second press of `Enter` submitting the form.
Copy link

changeset-bot bot commented Apr 23, 2024

⚠️ No Changeset found

Latest commit: c41e45f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

}
if (!multiple.get()) {
closeMenu();
if (!multiple.get()) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this should be inside the highlighted check. We should always close it when pressing enter. The prevent default looks good though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants