Skip to content

Commit

Permalink
fix(comp:textarea,pro:textarea): scrollHeight miscalculated on firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 authored and danranVm committed Nov 18, 2022
1 parent 67698a9 commit c61d7b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/components/textarea/src/composables/useAutoRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export function useAutoRows(
function getTextareaScrollHeight() {
return measureTextarea(textareaRef.value!, textarea => {
textarea.value = textareaRef.value!.value

// trigger reflow to ensure scrollHeight is calculated when referenced
void textarea.scrollHeight
return getHeightByScrollHeight(textarea.scrollHeight, boxSizingData.value)
})
}
Expand All @@ -82,6 +85,9 @@ export function useAutoRows(
measureTextarea(textareaRef.value!, textarea => {
textarea.style.height = ''
textarea.value = textarea.placeholder

// trigger reflow to ensure scrollHeight is calculated when referenced
void textarea.scrollHeight
cachedPlaceholderHeight = getHeightByScrollHeight(textarea.scrollHeight, boxSizingData.value)
})
}
Expand Down
3 changes: 3 additions & 0 deletions packages/pro/textarea/src/composables/useRowsCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function useRowCounts(
textarea,
el => {
el.value = line || 'x'

// trigger reflow to ensure scrollHeight is calculated when referenced
void el.scrollHeight
return Math.round((el.scrollHeight - paddingSize) / lineHeight.value)
},
true,
Expand Down

0 comments on commit c61d7b2

Please sign in to comment.