mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 19:30:37 +01:00
fix(Textarea): autoresize (#43)
This commit is contained in:
committed by
GitHub
parent
571e907acd
commit
ba643d9faa
@@ -104,15 +104,19 @@ export default {
|
|||||||
|
|
||||||
const autoResize = () => {
|
const autoResize = () => {
|
||||||
if (props.autoresize) {
|
if (props.autoresize) {
|
||||||
|
textarea.value.rows = props.rows
|
||||||
|
|
||||||
const styles = window.getComputedStyle(textarea.value)
|
const styles = window.getComputedStyle(textarea.value)
|
||||||
const paddingTop = parseInt(styles.paddingTop)
|
const paddingTop = parseInt(styles.paddingTop)
|
||||||
const paddingBottom = parseInt(styles.paddingBottom)
|
const paddingBottom = parseInt(styles.paddingBottom)
|
||||||
const padding = paddingTop + paddingBottom
|
const padding = paddingTop + paddingBottom
|
||||||
const initialHeight = (parseInt(styles.height) - padding) / textarea.value.rows
|
const lineHeight = parseInt(styles.lineHeight)
|
||||||
const scrollHeight = textarea.value.scrollHeight - padding
|
const { scrollHeight } = textarea.value
|
||||||
const newRows = Math.ceil(scrollHeight / initialHeight)
|
const newRows = (scrollHeight - padding) / lineHeight
|
||||||
|
|
||||||
textarea.value.rows = newRows
|
if (newRows > props.rows) {
|
||||||
|
textarea.value.rows = newRows
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user