Textarea
A text field for several lines. It grows with its content.
Native <textarea>
<script setup lang="ts">
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
</script>
<template>
<div class="field">
<Label for="message">Message</Label>
<Textarea id="message" placeholder="Type your message here." />
</div>
</template>
<style scoped>
.field {
display: grid;
gap: var(--dui-space-2);
width: min(100%, 20rem);
}
</style>
Installation
npx distill-ui add textarea- Set up the tokens once, if you haven't: see manual installation.
- Copy these files into your project:
<script setup lang="ts">
const model = defineModel<string>();
</script>
<template>
<textarea v-model="model" class="textarea"></textarea>
</template>
<!--
Options you can set from a parent or on the textarea itself:
--dui-textarea-min-height, --dui-textarea-border, --dui-textarea-radius, --dui-textarea-bg
-->
<style scoped>
.textarea {
display: flex;
width: 100%;
min-height: var(--dui-textarea-min-height, 4rem);
/* Grows with its content in browsers that support it. */
field-sizing: content;
padding: var(--dui-space-2) var(--dui-space-2-5);
border: 1px solid var(--dui-textarea-border, var(--dui-color-input));
border-radius: var(--dui-textarea-radius, var(--dui-radius-md));
background: var(--dui-textarea-bg, var(--dui-color-control));
color: var(--dui-color-foreground);
font: inherit;
font-size: var(--dui-text-sm);
line-height: var(--dui-text-sm-line-height);
box-shadow: var(--dui-shadow-xs);
outline: none;
transition:
border-color var(--dui-duration-fast) var(--dui-ease-out),
box-shadow var(--dui-duration-fast) var(--dui-ease-out);
&::placeholder {
color: var(--dui-color-muted-foreground);
}
&:focus-visible {
border-color: var(--dui-color-ring);
box-shadow: 0 0 0 var(--dui-ring-width)
color-mix(in oklch, var(--dui-color-ring) 50%, transparent);
}
&[aria-invalid='true'] {
border-color: var(--dui-color-destructive);
box-shadow: 0 0 0 var(--dui-ring-width)
color-mix(in oklch, var(--dui-color-destructive) 20%, transparent);
}
&:disabled {
cursor: not-allowed;
opacity: 0.5;
}
}
</style>
export { default as Root, default as Textarea } from './Textarea.vue';
Customizing
Set any of these on the component or on a parent element. See Customizing for how they work.
| Custom property | Default |
|---|---|
--dui-textarea-min-height | 4rem |
--dui-textarea-border | var(--dui-color-input) |
--dui-textarea-radius | var(--dui-radius-md) |
--dui-textarea-bg | var(--dui-color-control) |