Skip to content

feat(useTextareaAutosize): add optional maxHeight to limit autosize growth#5324

Merged
antfu merged 6 commits into
vueuse:mainfrom
palamarchukser:fix/use-textarea-autosize-max-height
Apr 28, 2026
Merged

feat(useTextareaAutosize): add optional maxHeight to limit autosize growth#5324
antfu merged 6 commits into
vueuse:mainfrom
palamarchukser:fix/use-textarea-autosize-max-height

Conversation

@palamarchukser

@palamarchukser palamarchukser commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

useTextareaAutosize currently grows the applied size to match the full scrollHeight.

This becomes problematic when using styleProp: 'minHeight', which is the documented approach when a textarea also uses rows. In that case, the element keeps growing indefinitely and there is no built-in way to clamp autosize growth.

Using CSS max-height does not reliably solve this when minHeight is used, because the composable continuously increases the applied min-height value to match scrollHeight.

This PR adds an optional maxHeight option to useTextareaAutosize.

When provided, the computed autosize value is clamped before being applied:

  • without maxHeight, behavior remains unchanged
  • with maxHeight, the applied size becomes Math.min(scrollHeight, maxHeight)

This allows limiting textarea growth while still keeping autosize behavior.

Additional context

This change is fully backward compatible because maxHeight is optional and existing behavior is preserved when it is not provided.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 16, 2026
@OrbisK OrbisK changed the title fix(useTextareaAutosize): add optional maxHeight to limit autosize growth feat(useTextareaAutosize): add optional maxHeight to limit autosize growth Apr 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Apr 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vueuse/components

pnpm add https://pkg.pr.new/@vueuse/components@5324
npm i https://pkg.pr.new/@vueuse/components@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/core

pnpm add https://pkg.pr.new/@vueuse/core@5324
npm i https://pkg.pr.new/@vueuse/core@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/electron

pnpm add https://pkg.pr.new/@vueuse/electron@5324
npm i https://pkg.pr.new/@vueuse/electron@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/firebase

pnpm add https://pkg.pr.new/@vueuse/firebase@5324
npm i https://pkg.pr.new/@vueuse/firebase@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/integrations

pnpm add https://pkg.pr.new/@vueuse/integrations@5324
npm i https://pkg.pr.new/@vueuse/integrations@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/math

pnpm add https://pkg.pr.new/@vueuse/math@5324
npm i https://pkg.pr.new/@vueuse/math@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/metadata

pnpm add https://pkg.pr.new/@vueuse/metadata@5324
npm i https://pkg.pr.new/@vueuse/metadata@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/nuxt

pnpm add https://pkg.pr.new/@vueuse/nuxt@5324
npm i https://pkg.pr.new/@vueuse/nuxt@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/router

pnpm add https://pkg.pr.new/@vueuse/router@5324
npm i https://pkg.pr.new/@vueuse/router@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/rxjs

pnpm add https://pkg.pr.new/@vueuse/rxjs@5324
npm i https://pkg.pr.new/@vueuse/rxjs@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/shared

pnpm add https://pkg.pr.new/@vueuse/shared@5324
npm i https://pkg.pr.new/@vueuse/shared@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/skills

pnpm add https://pkg.pr.new/@vueuse/skills@5324
npm i https://pkg.pr.new/@vueuse/skills@5324
yarn add https://pkg.pr.new/@vueuse/[email protected]

commit: a3b1242

@codecov

codecov Bot commented Apr 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.38%. Comparing base (e890d4c) to head (a3b1242).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5324      +/-   ##
==========================================
+ Coverage   65.07%   65.38%   +0.31%     
==========================================
  Files         346      346              
  Lines        8163     8167       +4     
  Branches     2514     2505       -9     
==========================================
+ Hits         5312     5340      +28     
+ Misses       2322     2304      -18     
+ Partials      529      523       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 2, 2026
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 22, 2026
OrbisK
OrbisK previously approved these changes Apr 23, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 23, 2026
antfu
antfu previously approved these changes Apr 28, 2026
@antfu
antfu enabled auto-merge April 28, 2026 05:47
@9romise
9romise dismissed stale reviews from antfu and OrbisK via a3b1242 April 28, 2026 09:50
@antfu
antfu added this pull request to the merge queue Apr 28, 2026
Merged via the queue into vueuse:main with commit 1a3e572 Apr 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants