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] Autocomplete with multiline TextField incorrectly handle cursor movement and onMouseDown events. #19132

Closed
2 tasks done
justtol opened this issue Jan 8, 2020 · 3 comments · Fixed by #19232
Closed
2 tasks done
Labels
component: autocomplete This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@justtol
Copy link
Contributor

justtol commented Jan 8, 2020

Autocomplete component with multiline text field doesn't handle cursor correctly on mouse click when a text was entered.

Reproduced on the following code:
<Autocomplete freeSolo renderInput={params => (<TextField {...params} multiline />)}/>

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

  1. Input any text into Autocomplete with mulitline textfield.
  2. Click to any part of the entered text
  3. Cursor is not moved to the clicked text.
  4. If a TextField is not multilined then behaviour is correct and cursor is placed correctly when you click to the entered text.

Expected Behavior 🤔

  1. Input any text into Autocomplete with mulitline textfield.
  2. Click to any part of the entered text
  3. Cursor is moved to the clicked text.

Context 🔦

I would like to use Autocomplete component to enter address with suggesstions. I can use Autocomplete with TextField without multiline on desktop browser, but it is not suitable for mobile browser because address is quite a long string.

Your Environment 🌎

Tech Version
Material-UI v4.8.3
Material-ui/lab 4.0.0-alpha.39
React 16.12.0
Browser Chrome 79.0.3945.88
@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Jan 8, 2020
@oliviertassinari
Copy link
Member

Do you have a reproduction?

@oliviertassinari oliviertassinari added the status: waiting for author Issue with insufficient information label Jan 11, 2020
@justtol
Copy link
Contributor Author

justtol commented Jan 11, 2020

It is reproducible here:
https://codesandbox.io/s/material-ui-358fg

@oliviertassinari oliviertassinari added new feature New feature or request good first issue Great for first contributions. Enable to learn the contribution process. and removed status: waiting for author Issue with insufficient information labels Jan 11, 2020
@oliviertassinari
Copy link
Member

@justtol Thanks, it's interesting. The component wasn't designed to support a textarea, and I have doubt that we should. However, I think that we could change the logic to check for the id instead of the type of the node:

diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index de0bfd292..67cbd7dcd 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -734,7 +734,7 @@ export default function useAutocomplete(props) {

   // Prevent input blur when interacting with the combobox
   const handleMouseDown = event => {
-    if (event.target.nodeName !== 'INPUT') {
+    if (event.target.getAttribute('id') !== id) {
       event.preventDefault();
     }
   };

What do you think? Do you want to submit a pull request? :)

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! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants