Skip to content

Commit 02dda74

Browse files
committed
Tenfold increase in style parsing performance
1 parent e08a89b commit 02dda74

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

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)