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

[material-ui][Autocomplete] click on helperText inside of Autocomplete component triggers input focus/option selection #41931

Closed
AndreyOstrovnev opened this issue Apr 17, 2024 · 7 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists package: material-ui Specific to @mui/material

Comments

@AndreyOstrovnev
Copy link

AndreyOstrovnev commented Apr 17, 2024

Steps to reproduce

Link to live example: link

Steps:

  1. Click on helper text area to focus autocomplete input

helper text area:
autocomplete_example

Current behavior

Autocomplete input is focused, option selection area is opened

Expected behavior

I'm expecting nothing should happen, clicking underneath input should not cause input focus

Context

No response

Your environment

No response

Search keywords: Autocomplete

@AndreyOstrovnev AndreyOstrovnev added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 17, 2024
@imran-yasin
Copy link

imran-yasin commented Apr 17, 2024

Check this Link
Hi, @AndreyOstrovnev

I've use the propagation method to stop the parent (Autocomplete) from reacting when you click on the child ( that is the TextField ). Now nothing should happen, clicking underneath input. Thanks

@ZeeshanTamboli
Copy link
Member

Thanks for the solution, @imran-yasin.

@AndreyOstrovnev, the issue occurs because the helper text is rendered within the Text Field component (using the FormHelperText component). Therefore, clicking on the helper text is treated as clicking on the Text Field itself. Following @imran-yasin's solution to stop the event propagation should resolve this issue. If that doesn't work, consider rendering the input component and FormHelperText component separately in the renderInput callback of the Autocomplete.

@ZeeshanTamboli ZeeshanTamboli added package: material-ui Specific to @mui/material component: autocomplete This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 17, 2024
@AndreyOstrovnev
Copy link
Author

Hi @imran-yasin, thanks for the solution but your fix disables the event only on text. The content of helperText is wrapped in "p" tag which is still causes focus on input. So clicking right next to helper text will still trigger focus event. E.g. here:
Untitled

@imran-yasin
Copy link

imran-yasin commented Apr 17, 2024

@AndreyOstrovnev Thank you for pointing that out! To prevent the focus event from being triggered when clicking next to the helper text, we need to apply the event handler to the entire helper text area, including the surrounding p tag

Check this Updated Version

@AndreyOstrovnev
Copy link
Author

@imran-yasin I got your idea of fixing it, thanks for helping! There are still some places when the background area is clickable because p tag you added doesn't exactly match with outer tag added by MUI: <p class="MuiFormHelperText-root MuiFormHelperText-sizeMedium MuiFormHelperText-contained css-1wc848c-MuiFormHelperText-root" id="combo-box-demo-helper-text"> .... I achieved the expected behavior by moving out helper text completely out of Autocomplete component at the same level as a sibling. But the thing is for me it looked like a workaround of existing behavior.

@AndreyOstrovnev
Copy link
Author

Hi @ZeeshanTamboli, since the issue is closed, I'm assuming there is no unexpected behavior and no plan to fix it?

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Apr 17, 2024

@AndreyOstrovnev, upon further consideration, I agree with your assessment. Rendering the helper text separately from the input seems like the best approach. As demonstrated in the following demo: https://mui.com/material-ui/react-text-field/#helper-text, clicking on the helper text does not focus the input. This issue is duplicate of #26153. So I am marking it as a duplicate. Follow #26153 for more updates.

@ZeeshanTamboli ZeeshanTamboli closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
@ZeeshanTamboli ZeeshanTamboli added the duplicate This issue or pull request already exists label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

3 participants