Skip to content
On this page

useTextareaAutosize

Automatically update the height of a textarea depending on the content.

Demo

Category
Last Changed
last month
Type, the textarea will grow:

Usage

<script setup lang="ts">
const { textarea, input } = useTextareaAutosize()
</script>

<template>
  <textarea
    ref="textarea"
    v-model="input"
    class="resize-none"
    placeholder="What's on your mind?"
  />
</template>
<script setup lang="ts">
const { textarea, input } = useTextareaAutosize()
</script>

<template>
  <textarea
    ref="textarea"
    v-model="input"
    class="resize-none"
    placeholder="What's on your mind?"
  />
</template>

Type Declarations

export interface UseTextareaAutosizeOptions {
  /** Textarea element to autosize. */
  element?: MaybeRef<HTMLTextAreaElement | undefined>
  /** Textarea content. */
  input?: MaybeRef<string | undefined>
  /** Watch sources that should trigger a textarea resize. */
  watch?: WatchSource | Array<WatchSource>
  /** Function called when the textarea size changes. */
  onResize?: () => void
}
export declare function useTextareaAutosize(
  options?: UseTextareaAutosizeOptions
): {
  textarea: Ref<HTMLTextAreaElement>
  input: Ref<string>
  triggerResize: () => void
}
export declare type UseTextareaAutosizeReturn = ReturnType<
  typeof useTextareaAutosize
>
export interface UseTextareaAutosizeOptions {
  /** Textarea element to autosize. */
  element?: MaybeRef<HTMLTextAreaElement | undefined>
  /** Textarea content. */
  input?: MaybeRef<string | undefined>
  /** Watch sources that should trigger a textarea resize. */
  watch?: WatchSource | Array<WatchSource>
  /** Function called when the textarea size changes. */
  onResize?: () => void
}
export declare function useTextareaAutosize(
  options?: UseTextareaAutosizeOptions
): {
  textarea: Ref<HTMLTextAreaElement>
  input: Ref<string>
  triggerResize: () => void
}
export declare type UseTextareaAutosizeReturn = ReturnType<
  typeof useTextareaAutosize
>

Source

SourceDemoDocs

Contributors

Jelf
Anthony Fu
Enzo Innocenzi

Changelog

No recent changes

Released under the MIT License.