Giter VIP home page Giter VIP logo

Comments (7)

CMTegner avatar CMTegner commented on September 28, 2024 2

Reproducible in IE11 on Windows 8.1:

  1. Navigate to https://reactcommunity.org/react-autocomplete/async-data/
  2. Type 'A' in the input
  3. Observe that the 'Alabama' is highlighted in the autocomplete menu
  4. Type 'L' in the input
  5. Observe that the input value is 'LA', expected: 'AL'

I'm not sure what causes this, but if no one else has time I'll try to have a look this weekend.

from react-autocomplete.

HenriJ avatar HenriJ commented on September 28, 2024

Hi @CMTegner . Did you have any luck finding the root cause ? We are stuck because of this problem too, and can have a look also if it can help.

from react-autocomplete.

CMTegner avatar CMTegner commented on September 28, 2024

I've had little look at the problem. My initial suspicion was that input#setSelectionRange() (which is invoked when Autocomplete fills the input with the top result) was bugging out in IE, and that's sort of what's happening. To exclude the possibility of setSelectionRange() being completely borked on IE I made a quick test page:

<!doctype html>
<html>
<head>
  <title>setSelectionRange test</title>
</head>
<body>
  <input type="text" value="foobar">
  <script type="text/javascript">
    var input = document.querySelector('input');
    input.focus();
    input.setSelectionRange(1, 6);
  </script>
</body>
</html>

Load that up in IE11, type a character, success.

After having played around with setSelectionRange for a while, I came to the conclusion that if you create a range with a non-zero length, the caret (or at least the internal caret state position) is moved to position 0 (the start of the input). In other words, if you use setSelectionRange to place the caret (end = start) after updating the input value, things work as expected. The problem occurs when you create an actual text selection range (end > start).

My current theory is that Autocomplete's usage of setSelectionRange() is somehow interfering with React's focus/caret positioning logic. I haven't had time to dig any deeper.

from react-autocomplete.

HenriJ avatar HenriJ commented on September 28, 2024

Not sure exactly why it behaves like that (as you say, it might be interferences between React and setSelectionRange), but I found a workaround that seems to fix the issue : forcing the position of the caret in the callback of the setState() that was causing the problem.

@CMTegner @shiitake Could you confirm that HenriJ@3d5a3e8 fixes the issue for you ?

from react-autocomplete.

CMTegner avatar CMTegner commented on September 28, 2024

@HenriJ I don't even want to know what made you try that... I swear I tried just about everything yesterday in an attempt to find a workaround. Even after having tested your workaround for a couple of hours I still don't 100% understand why it works. The closest I've come to explain it is this:

screen shot 2016-03-24 at 12 14 24

That's Chrome (on Mac) and IE11 side by side. You can see that the setState() callback in handleKeyDown() reports the correct caret/selection state in Chrome, but IE reports it as (0,0). Ignore the non-deterministic autocomplete suggestions, I eventually reduced the list in lib/utils.js to exclude that as a possibility.

Anyway, huge thanks! I made a PR which I need @sprjr to look at ASAP, since this is a blocker for IE usage.

from react-autocomplete.

whichsteveyp avatar whichsteveyp commented on September 28, 2024

Sorry again for the delays here. This has been in 1.0.0-rc2, which I've tagged and published to npm. Unfortunately I'm headed to China for most of the rest of the month. We should probably chat with @ryanflorence about adding more contributors to the project if something more pressing comes up. There's a backlog of issues and PRs open that I'd like to try and work through as well, to keep the component moving and up to date.

Hopefully this release unblocks folks!

from react-autocomplete.

CMTegner avatar CMTegner commented on September 28, 2024

@sprjr no worries, I'm happy just seeing some movement at all :)

from react-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.