Skip to content

Commit

Permalink
fix(Textarea): autoresize (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarroufin committed Apr 4, 2022
1 parent 571e907 commit ba643d9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,19 @@ export default {
const autoResize = () => {
if (props.autoresize) {
textarea.value.rows = props.rows
const styles = window.getComputedStyle(textarea.value)
const paddingTop = parseInt(styles.paddingTop)
const paddingBottom = parseInt(styles.paddingBottom)
const padding = paddingTop + paddingBottom
const initialHeight = (parseInt(styles.height) - padding) / textarea.value.rows
const scrollHeight = textarea.value.scrollHeight - padding
const newRows = Math.ceil(scrollHeight / initialHeight)
const lineHeight = parseInt(styles.lineHeight)
const { scrollHeight } = textarea.value
const newRows = (scrollHeight - padding) / lineHeight
textarea.value.rows = newRows
if (newRows > props.rows) {
textarea.value.rows = newRows
}
}
}
Expand Down

1 comment on commit ba643d9

@vercel
Copy link

@vercel vercel bot commented on ba643d9 Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.