Giter Club home page Giter Club logo

Comments (6)

cgat avatar cgat commented on July 24, 2024 1

I noticed this happening when my element was originally being rendered with display: none. In this case, the placeholder does not have a length and the element length fails to get set properly.

from react-input-autosize.

ericgio avatar ericgio commented on July 24, 2024 1

@JedWatson: From what I can tell, the issue is due to input styles only being set in componentDidMount. Moving that line here seems to solve the problem.

Happy to submit a PR for this, just wasn't sure if there was a specific reason you were only setting the styles once.

from react-input-autosize.

ericgio avatar ericgio commented on July 24, 2024

I'm seeing this issue as well, both when a parent is initially rendered with display: none and when props change that should affect the input size. Even when forcing a prop change to the input, however, I'm not seeing it update as I would expect.

from react-input-autosize.

JedWatson avatar JedWatson commented on July 24, 2024

If someone can provide a link (e.g. to codesandbox) or adds an example that reproduces this I'd be happy to take a look at it

from react-input-autosize.

thomaslc66 avatar thomaslc66 commented on July 24, 2024

Hello @JedWatson I have the same problem. Here you can find some of my implementation.
It's a really wierd behavior.

I have 2 lists that used the same method to render a input. They Both called renderColumn
First list is ok, second list isn't. I use a tab to switch between first list (password) and second (licence).
All state is in redux as i use redux-form.

const renderColumn = props => {
  const {
    index,
    renderToaster,
    input: { name, onChange, value },
    placeholder,
    ...restProps
  } = props;
  return (
    <Column
      onChange={onChange}
      renderToaster={renderToaster}
      text={value}
      maxLength={50}
      name={name}
      placeholder={placeholder}
      restProps={restProps}
    />
  );
};
<MDBTableBody>
       {fields.map((data, index) => {
            return (
              <tr key={"key_" + index}>
                <DeleteRow deleteARow={() => fields.remove(index)} />
                <Field
                  name={`${data}.login`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={LOGIN}
                />
                <Field
                  name={`${data}.password`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={PASSWORD}
                />
                <Field
                  name={`${data}.account`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={ACCOUNT}
                />
              </tr>
            );
          })}
</MDBTableBody>
<MDBTableBody>
          {fields.map((data, index) => {
            return (
              <tr key={"key_" + index}>
                <DeleteRow deleteARow={() => fields.remove(index)} />
                <Field
                  name={`${data}.buyDate`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={BUYDATE}
                />
                <Field
                  name={`${data}.key`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={KEY}
                />
                <Field
                  name={`${data}.program`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={PROGRAM}
                />
                <Field
                  name={`${data}.computer`}
                  component={renderColumn}
                  renderToaster={renderToaster}
                  placeholder={COMPUTER}
                />
              </tr>
            );
          })}
</MDBTableBody>
//render method of the Column Component
render() {
    const {
      text,
      indexPath,
      status,
      name,
      index,
      maxLength,
      onClick,
      placeholder
    } = this.props;
    return (
      <td className='align-vertical'>
        <AutosizeInput
          className='list_input'
          disabled={status}
          onClick={onClick}
          value={text}
          name={name}
          onChange={e => {
            this.props.onChange(e, indexPath);
          }}
          index={index}
          maxLength={maxLength}
          placeholder={placeholder}
        />
        <MDBIcon
          far
          icon='clone'
          className={
            this.state.isHovered ? "icon_clone_hover" : "icon_clone text-muted"
          }
          onClick={() => this.copyText(text)}
          onMouseEnter={this.handleHover}
          onMouseLeave={this.handleHover}
        />
      </td>
    );
  }
}

Here you can see, first line is not ok, but when i click on "Nouveau" button, the new line is ok.

image

Don't know if this can help you. But when i move my mouse hover the copy icon, then the autosize input take the good size. (my hover method only change the cursor of the mouse to display a hand cursor)

Hope it will help.

Edit:
Here is a picture of the state of the component:
image

from react-input-autosize.

ozluy avatar ozluy commented on July 24, 2024

I just created a new NPM module please check it out:

  • 252 byte size only 10% of react-input-autosize (2.3KB)

https://github.com/ozluy/calculate-text-width
image

from react-input-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.