Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useTextareaAutosize.md
1---2category: Browser3---45# useTextareaAutosize67Automatically update the height of a textarea depending on the content.89## Usage1011### Simple example1213```vue14<script setup lang="ts">15import { useTextareaAutosize } from '@vueuse/core'1617const { textarea, input } = useTextareaAutosize()18</script>1920<template>21<textarea22ref="textarea"23v-model="input"24class="resize-none"25placeholder="What's on your mind?"26/>27</template>28```2930::: info3132It's recommended to reset the scrollbar styles for the textarea element to avoid incorrect height values for large amounts of text.3334```css35textarea {36-ms-overflow-style: none;37scrollbar-width: none;38}3940textarea::-webkit-scrollbar {41display: none;42}43```4445:::4647### With `rows` attribute4849If you need support for the rows attribute on a textarea element, then you should set the `styleProp` option to `minHeight`.5051```vue52<script setup lang="ts">53import { useTextareaAutosize } from '@vueuse/core'5455const { textarea, input } = useTextareaAutosize({ styleProp: 'minHeight' })56</script>5758<template>59<textarea60ref="textarea"61v-model="input"62class="resize-none"63placeholder="What's on your mind?"64rows="3"65/>66</template>67```6869### With `maxHeight`7071Use the `maxHeight` option to cap the textarea height in pixels while keeping autosize behavior.7273```vue74<script setup lang="ts">75import { useTextareaAutosize } from '@vueuse/core'7677const { textarea, input } = useTextareaAutosize({78maxHeight: 180,79styleProp: 'minHeight',80})81</script>8283<template>84<textarea85ref="textarea"86v-model="input"87class="resize-none"88placeholder="What's on your mind?"89rows="3"90/>91</template>92```9394## Type Declarations9596```ts97export interface UseTextareaAutosizeOptions extends ConfigurableWindow {98/** Textarea element to autosize. */99element?: MaybeRef<HTMLTextAreaElement | undefined | null>100/** Textarea content. */101input?: MaybeRef<string>102/** Maximum autosized height in pixels. */103maxHeight?: number104/** Watch sources that should trigger a textarea resize. */105watch?: WatchSource | MultiWatchSources106/** Function called when the textarea size changes. */107onResize?: () => void108/** Specify style target to apply the height based on textarea content. If not provided it will use textarea it self. */109styleTarget?: MaybeRef<HTMLElement | undefined>110/** Specify the style property that will be used to manipulate height. Can be `height | minHeight`. Default value is `height`. */111styleProp?: "height" | "minHeight"112}113export interface UseTextareaAutosizeReturn {114textarea: Ref<HTMLTextAreaElement | undefined | null>115input: Ref<string>116triggerResize: () => void117}118export declare function useTextareaAutosize(119options?: UseTextareaAutosizeOptions,120): UseTextareaAutosizeReturn121```122