Improve $.autoSizeTextArea with padded textareas and different fonts.
Review Request #6464 — Created Oct. 19, 2014 and submitted
$.autoSizeTextArea
worked very well when the proxy element and
<textarea>
matched up perfectly (in terms of margins/padding and fonts)
and padding wasn't used in the text area. However, if one of these
conditions weren't true, incorrect heights would end up being
calculated.We now assume that a minimum height is the full height of the field,
which may include padding. Since we are setting usingheight()
, which
expects a content height without padding, we need to subtract any
padding that may be there. This helps to provide the heights that the
caller would expect.We also set some sane defaults for the proxy element, removing any
margins, padding, and borders that may be there, and ensuring the font
is the same as the textarea.This also updates
setMinHeight()
to trigger an auto-size. It was strange
that it didn't before, and that it was up to the caller to explicitly
trigger an auto-size.
Tested with some of the work I'm doing for a hybrid textarea/CodeMirror widget.
I was able to get consistent minimum heights, which was failing before.
Description | From | Last Updated |
---|---|---|
Can we call .height() and assign it once to a variable, so we don't have to do it twice? |
david |
- Change Summary:
-
Only call
height()
once. - Commit:
-
8426f39b5f2f4da238c89e74f26853b93b44bb87b9c84b71f547d11d963b9800e037d46754eee52e