LeaVerou / stretchy

Form element autosizing, the way it should be
https://stretchy.verou.me/
Other
1.27k stars 87 forks source link

does not autosize textarea with min-height #23

Closed tinynow closed 7 years ago

tinynow commented 8 years ago

Here is an example of the bug: http://codepen.io/tinynow/pen/MyXZNL

anfedorov commented 7 years ago

fix on line 57:

            else if (cs.boxSizing == "content-box") {
-               offset = -element.clientHeight;
+               offset = -element.clientHeight + parseFloat(cs.minHeight);
            }
anfedorov commented 7 years ago

(pull request inc... soon)

macfire commented 7 years ago

For textareas with min-height set, I had to change line 60 as follows to not have extra offset:

(stretchy.js - line 60)

               if (offset > parseFloat(cs.minHeight)) {
                    element.style.height = element.scrollHeight + offset + "px";
                } else {
                    element.style.height = element.scrollHeight + "px";
                }
anfedorov commented 7 years ago

do I understand correctly that this conditional is essentially checking whether cs.boxSizing is "content-box"? could you make a simple codepen of the issue?

anfedorov commented 7 years ago

seems to work fine with the latest code: http://codepen.io/anfedorov/pen/xqWPja

no?

macfire commented 7 years ago

My default CSS style is set with box-sizing: border-box; If I change it to box-sizing: content-box, then the code works as you show. (But would require changing my CSS)

http://codepen.io/anon/pen/XMEzxq

anfedorov commented 7 years ago

got it. opened #28.

macfire commented 7 years ago

The change is much simpler than I did with the conditional.

My new change is in ~line 55:

                if (cs.boxSizing == "border-box") {
                    offset = 0; // element.offsetHeight;
                }

This is for Safari on Mac desktop. I have not yet tested other browsers.

Update: Changing the offset = 10, instead of 0 (for 'border-box') gets rid of the scrollbar in Firefox (Mac).

anfedorov commented 7 years ago

makes sense. let's discuss on #28. sounds like some automated cross-browser tests would be of some help here, as well...