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

Unexpected Form Submission on Combobox having no results #3323

Open
marilari88 opened this issue Jan 12, 2024 · 9 comments
Open

Unexpected Form Submission on Combobox having no results #3323

marilari88 opened this issue Jan 12, 2024 · 9 comments

Comments

@marilari88
Copy link

marilari88 commented Jan 12, 2024

Current behavior

When using the ComboBox and performing a search that results in an empty list, pressing the 'Enter' key triggers the form submission

Steps to reproduce the bug

  1. Open sandbox: https://stackblitz.com/edit/stackblitz-starters-a6j6lm?file=src%2FApp.tsx
  2. Open the select combobox
  3. Type 'asdasd'
  4. Press 'Enter'

Expected behavior

The form submission should not be triggered as the combobox field is not a part of the form

Workaround

add form attribute to the combobox

Or #3323 (comment)

Possible solutions

No response

@diegohaz
Copy link
Member

The combobox is rendered within the form element in the DOM, making it technically part of it. I'm not sure if there's a way we can address this in the library without impacting those who genuinely want a combobox within a form. But I'm open to suggestions.

As an alternative, you can render the SelectPopover component using the portal prop. This ensures it's not rendered within the form in the DOM:

<SelectPopover portal>

@cloud-walker
Copy link
Contributor

If I understand the issue correctly it is because the focus does not remain trapped inside the Combobox popover, when no ComboboxItem are rendered, maybe we should simulate that focus anyway?

@cloud-walker
Copy link
Contributor

A possible workaround may be to render a "fake" ComboboxItem during the "No results" state

@marilari88
Copy link
Author

@diegohaz Thank you for your suggestion. I appreciate your responsiveness to the issue.

While using portal with SelectPopover seems like a promising solution, I encountered a limitation in that the dialog prevents interaction with elements outside itself

@diegohaz
Copy link
Member

While using portal with SelectPopover seems like a promising solution, I encountered a limitation in that the dialog prevents interaction with elements outside itself

Sounds like you're describing modal. The portal prop shouldn't behave like that. If it does, it's likely a bug, and a repro would be appreciated.

@georgekaran
Copy link
Contributor

While using portal with SelectPopover seems like a promising solution, I encountered a limitation in that the dialog prevents interaction with elements outside itself

You could use the getPersistentElements to allow interaction with external elements.

<SelectPopover portal className="select-dialog">
<Modal
  {...props}
  getPersistentElements={() => document.querySelector('.select-dialog')}
/>

@cloud-walker
Copy link
Contributor

While using portal with SelectPopover seems like a promising solution, I encountered a limitation in that the dialog prevents interaction with elements outside itself

Sounds like you're describing modal. The portal prop shouldn't behave like that. If it does, it's likely a bug, and a repro would be appreciated.

I think that what @marilari88 meant, is that combining the combobox with portal inside a form, inside a modal dialog, it breaks:

<Modal>
  <form>
    <Combobox portal>

@diegohaz
Copy link
Member

If that's the case and Modal is a component that uses the Ariakit Dialog component, I'd still appreciate a separate bug report. It's supposed to work seamlessly. Check out the Dialog with Menu example where the nested Menu component uses the portal prop and gets rendered within a modal dialog. The behavior for SelectPopover should be pretty similar.

@jasikpark
Copy link

https://open-ui.org/components/selectlist/#keyboard-behavior suggests that this is correct behavior?

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

No branches or pull requests

5 participants