Git Product home page Git Product logo

Comments (9)

HadrienPierart avatar HadrienPierart commented on August 22, 2024 3

Somehow, using the defaultvalue prop instead of the value prop fixes the issue and the cursor/caret works properly...

from react-textarea-autosize.

dancrew32 avatar dancrew32 commented on August 22, 2024 1

So basically use one or the other. Thanks @HadrienPierart!

// Uncontrolled.
<Textarea 
    defaultValue={this.state.foo} 
    onChange={(event) => this.setState({foo: event.target.value})}/>
// Controlled.
<Textarea value={this.state.foo}/>

from react-textarea-autosize.

jquense avatar jquense commented on August 22, 2024

addendum this may be a React bug. facebook/react#5386

Well something is definately causing this behavior in this component but not my other inputs so there is still something specific that this component but the async set may not be the actual issue.

from react-textarea-autosize.

sohwendy avatar sohwendy commented on August 22, 2024

A partial solution is to check if props and states have changed in shouldComponentUpdate.

This will work for most cases except typing [enter] in the middle of the text.

Hope to get a better solution

    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps, nextState) {
      for (const i in nextProps) {
        if (!(nextProps[i] ==  this.props[i])) {
          return true;
        }
      }
      for (const i in nextState) {
        if (!(nextState[i] == this.state[i])) {
          return true;
        }
      }
      return false;
    }

from react-textarea-autosize.

sunjay avatar sunjay commented on August 22, 2024

This is the same issue as seen here: reflux/refluxjs#43 (comment)

That's a link to a solution as well. Basically what @sohwendy is pointing to.

from react-textarea-autosize.

alex35mil avatar alex35mil commented on August 22, 2024

I don't think it has something w/ asynchronicity as I faced this issue w/ non-async code (sync redux action creator). It's a weird bug, b/c I render the same component in another part of the app, but it works fine.

from react-textarea-autosize.

alex35mil avatar alex35mil commented on August 22, 2024

I figured out what caused my issue: it was Modal component from react-overlays/react-bootstrap + any lib, that is child of Modal and is passing value to input/textarea from its local state. I confirmed this with 2 such libs (this one + my form validator). This case can be reproduced w/ the following scenario:

<Modal>
  <SomeLibThatPassesValueFormItsLocalStateToTextInputOrTextarea>
    <input type="text" value={props.value} />
  </SomeLibThatPassesValueFormItsLocalStateToTextInputOrTextarea>
</Modal>

On the props update I observe 2 re-renders in the input component:

  • updater triggered
  • updated value passed to the root component
  • first render w/ obsolete props
  • second w/ correct next props

This first render w/ obsolete props is the reason of this issue: input receives outdated (its current) value (at this point cursor is placed correctly), but next async update sets next value, vdom flushes this update and browser resets cursor position.

If I do this:

<SomeLibThatPassesValueFormItsLocalStateToTextInputOrTextarea>
  <Modal>
    <input type="text" value={props.value} />
  </Modal>
</SomeLibThatPassesValueFormItsLocalStateToTextInputOrTextarea>

There is only one render per update and everything works as expected.

It's quite late for me today, tomorrow I'll file an issue at react-overlays/react-bootstrap repo.

from react-textarea-autosize.

alex35mil avatar alex35mil commented on August 22, 2024

Issue: react-bootstrap/react-bootstrap#2323

from react-textarea-autosize.

Andarist avatar Andarist commented on August 22, 2024

I think there is no more issue here and going to close this now, if something stays unresolved, let me know and I reopen so we can work through it.

from react-textarea-autosize.

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.