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

Autocomplete clear button acting as type="submit" by default #39262

Closed
mattshipitfi opened this issue Oct 2, 2023 · 2 comments · Fixed by #39263
Closed

Autocomplete clear button acting as type="submit" by default #39262

mattshipitfi opened this issue Oct 2, 2023 · 2 comments · Fixed by #39263
Assignees
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base package: joy-ui Specific to @mui/joy

Comments

@mattshipitfi
Copy link

mattshipitfi commented Oct 2, 2023

Steps to reproduce 🕹

Hi, thanks for the great library, and sorry if this has been reported elsewhere.

Link to live example:
Here is a basic HTML repro that illustrates the problem:

<form>
    <button>mui autocomplete clear button</button>
    <input />
</form>

Steps :

  1. Add a mui-joy autocomplete field within a form tag
  2. Add a second text input
  3. Type some text into the second input, hit the enter key

Current behavior 😯

I've found what I think is a little usability issue and something that is probably very easy to change. Basically the clear button in a MUI-joy auto-complete field doesn't have the type attribute which means it defaults to type="submit".

This can result in the form getting submitted when the clear button is clicked or when the user hits the enter key in another field, if the field resides in a form tag.

Expected behavior 🤔

I think a clear button should never have the capability of submitting the form on behalf of the user as the clear button is explicitly for clearing the autocomplete field only, so my hope is you could add the type="button" attribute to the clear button

Context 🔦

I have my form fields wrapped in a form tag because 1) it's semantically correct, 2) I want to use native form validation which is very useful for mobile and reducing the number of translations needed (and I need to trigger it manually at a certain point).

The clear button being present as a submit button by default, tells the browser that the enter key should be able to trigger a form submit before I'm ready for them to submit.

Your environment 🌎

No response

@mattshipitfi mattshipitfi added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 2, 2023
@brijeshb42 brijeshb42 added component: autocomplete This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy labels Oct 2, 2023
@brijeshb42 brijeshb42 self-assigned this Oct 2, 2023
@brijeshb42 brijeshb42 removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 2, 2023
@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Oct 2, 2023
@brijeshb42
Copy link
Contributor

brijeshb42 commented Oct 3, 2023

Meanwhile, you can pass

<Autocomplete slotProps={{clearIndicator: {type: "button"}} ... />

as a workaround till the fix for it is merged.

@mattshipitfi
Copy link
Author

You're awesome, thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants