Skip to content

Commit

Permalink
Merge pull request #38 from silverwind/parsepixels
Browse files Browse the repository at this point in the history
Increase style parsing performance by 2x to 10x
  • Loading branch information
keithamus authored Apr 17, 2023
2 parents e08a89b + 02dda74 commit 9ad9a20
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export default function autosize(textarea, {viewportMarginBottom = 100} = {}) {

const textareaStyle = getComputedStyle(textarea)

const topBorderWidth = Number(textareaStyle.borderTopWidth.replace(/px/, ''))
const bottomBorderWidth = Number(textareaStyle.borderBottomWidth.replace(/px/, ''))
const topBorderWidth = parseFloat(textareaStyle.borderTopWidth)
const bottomBorderWidth = parseFloat(textareaStyle.borderBottomWidth)

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

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

Expand Down

0 comments on commit 9ad9a20

Please sign in to comment.