Skip to content

Commit 9ad9a20

Browse files
authored
Merge pull request #38 from silverwind/parsepixels
Increase style parsing performance by 2x to 10x
2 parents e08a89b + 02dda74 commit 9ad9a20

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export default function autosize(textarea, {viewportMarginBottom = 100} = {}) {
5050

5151
const textareaStyle = getComputedStyle(textarea)
5252

53-
const topBorderWidth = Number(textareaStyle.borderTopWidth.replace(/px/, ''))
54-
const bottomBorderWidth = Number(textareaStyle.borderBottomWidth.replace(/px/, ''))
53+
const topBorderWidth = parseFloat(textareaStyle.borderTopWidth)
54+
const bottomBorderWidth = parseFloat(textareaStyle.borderBottomWidth)
5555

5656
const isBorderBox = textareaStyle.boxSizing === 'border-box'
5757
const borderAddOn = isBorderBox ? topBorderWidth + bottomBorderWidth : 0
5858

59-
const maxHeight = Number(textareaStyle.height.replace(/px/, '')) + bottom
59+
const maxHeight = parseFloat(textareaStyle.height) + bottom
6060
const adjustedViewportMarginBottom = bottom < viewportMarginBottom ? bottom : viewportMarginBottom
6161
textarea.style.maxHeight = `${maxHeight - adjustedViewportMarginBottom}px`
6262

0 commit comments

Comments
 (0)