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## Type Declarations7071```ts72export interface UseTextareaAutosizeOptions extends ConfigurableWindow {73/** Textarea element to autosize. */74element?: MaybeRef<HTMLTextAreaElement | undefined | null>75/** Textarea content. */76input?: MaybeRef<string>77/** Watch sources that should trigger a textarea resize. */78watch?: WatchSource | MultiWatchSources79/** Function called when the textarea size changes. */80onResize?: () => void81/** Specify style target to apply the height based on textarea content. If not provided it will use textarea it self. */82styleTarget?: MaybeRef<HTMLElement | undefined>83/** Specify the style property that will be used to manipulate height. Can be `height | minHeight`. Default value is `height`. */84styleProp?: "height" | "minHeight"85}86export interface UseTextareaAutosizeReturn {87textarea: Ref<HTMLTextAreaElement | undefined | null>88input: Ref<string>89triggerResize: () => void90}91export declare function useTextareaAutosize(92options?: UseTextareaAutosizeOptions,93): UseTextareaAutosizeReturn94```95