Git Product home page Git Product logo

Comments (4)

joehave avatar joehave commented on August 26, 2024

I have a similar problem, but I can reproduce it in IE 8,9 and Chrome.
http://jsfiddle.net/a9k5t/4/

What appears to be happening is that the width of the hidden textarea is undefined, and thereby the mirror is being set to a width of 0px. This causes one character per line, and thereby one row per character.

There is a workaround to manually trigger the resize after showing it, but it does not seem to work without a short delay:
http://jsfiddle.net/a9k5t/5/

It's not ideal, as it may cause the textbox to temporarily display as huge. I've curious if anyone else has any ideas.

from autosize.

pasierb avatar pasierb commented on August 26, 2024

Same here, IE9, Chrome and FF. We load some html (includes form) via ajax and autosized textarea is oversized.

from autosize.

jackmoore avatar jackmoore commented on August 26, 2024

This is happening because the mirrored textarea copies the original textarea's width, but there could be other complications too. The DOM methods for taking measurements are going to report a width/height of 0 for hidden elements. Since the mirror element copies a width of 0, it ends up rendering with a large height to accommodate the words.

So this isn't surprising behavior. I wouldn't mind accounting for it, but I'm not sure if there is a clean way to handle it. I was just testing this, and I was surprised to find out that window.getComputedStyle will return the correct width/height if the element has a hidden display, but not if the element is hidden due to an ancestor element having a hidden display. Not sure why there is a differentiation there:

http://jsfiddle.net/a9k5t/9/

I expect that the best solution here is going to rely on users (you guys) not assigning plugins that need width/height calculations to hidden elements (sorry). Instead of hiding the parent element, you could give it a height/padding of 0 and hide the overflow. Also, if the textarea had a width/height style set (through CSS or JS), then the DOM methods could return those values.

from autosize.

jackmoore avatar jackmoore commented on August 26, 2024

Example hiding by using a 0 height parent:
http://jsfiddle.net/a9k5t/11/

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