Textarea
여러 줄 텍스트를 입력할 수 있는 textarea 요소 컴포넌트예요.
출처: Nuxt UI
본문
사용법
v-model 디렉티브로 Textarea의 값을 제어할 수 있어요.
<script setup lang="ts">
const value = ref("")
</script>
<template>
<UTextarea />
</template>
Rows
rows prop으로 행 수를 설정할 수 있어요. 기본값은 3이에요.
<template>
<UTextarea :rows="12" />
</template>
Placeholder
placeholder prop으로 플레이스홀더 텍스트를 설정할 수 있어요.
<template>
<UTextarea placeholder="Type something..." />
</template>
Autoresize
autoresize prop으로 Textarea 높이를 자동으로 조절할 수 있어요.
<script setup lang="ts">
const value = ref("This is a long text that will autoresize the height of the Textarea.")
</script>
<template>
<UTextarea v-model="value" autoresize />
</template>
자동 크기 조절 시 maxrows prop으로 최대 행 수를 설정할 수 있어요. 0으로 설정하면 Textarea는 무한히 자라요.
<script setup lang="ts">
const value = ref("This is a long text that will autoresize the height of the Textarea with a maximum of 4 rows.")
</script>
<template>
<UTextarea v-model="value" :maxrows="4" autoresize />
</template>
Color
color prop으로 Textarea가 포커스될 때의 링(ring) 색상을 바꿀 수 있어요.
<template>
<UTextarea color="neutral" highlight placeholder="Type something..." />
</template>
[!NOTE]
여기서
highlightprop은 포커스 상태를 보여 주기 위해 사용돼요. 검증 에러가 발생할 때 내부적으로 사용돼요.
Variant
variant prop으로 Textarea의 변형을 바꿀 수 있어요.
<template>
<UTextarea color="neutral" variant="subtle" :highlight="false" placeholder="Type something..." />
</template>
Size
size prop으로 Textarea의 크기를 바꿀 수 있어요.
<template>
<UTextarea size="xl" placeholder="Type something..." />
</template>
Icon
icon prop으로 Textarea 안에 Icon을 표시할 수 있어요.
<template>
<UTextarea icon="i-lucide-search" size="md" variant="outline" placeholder="Search..." :rows="1" />
</template>
leading과 trailing prop으로 아이콘 위치를 정하거나, leading-icon과 trailing-icon prop으로 각 위치에 다른 아이콘을 설정할 수 있어요.
<template>
<UTextarea trailing-icon="i-lucide-at-sign" placeholder="Enter your email" size="md" :rows="1" />
</template>
Avatar
avatar prop으로 Textarea 안에 Avatar를 표시할 수 있어요.
<template>
<UTextarea :avatar="{
src: 'https://github.com/nuxt.png',
loading: 'lazy'
}" size="md" variant="outline" placeholder="Search..." :rows="1" />
</template>
Loading
loading prop으로 Textarea에 로딩 아이콘을 표시할 수 있어요.
<template>
<UTextarea loading :trailing="false" placeholder="Search..." :rows="1" />
</template>
Loading Icon
loading-icon prop으로 로딩 아이콘을 커스터마이즈할 수 있어요. 기본값은 i-lucide-loader-circle이에요.
<template>
<UTextarea loading loading-icon="i-lucide-loader" placeholder="Search..." :rows="1" />
</template>
Nuxt:
[!TIP] 참고: /docs/getting-started/integrations/icons/nuxt#theme
app.config.ts의ui.icons.loading키에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] 참고: /docs/getting-started/integrations/icons/vue#theme
vite.config.ts의ui.icons.loading키에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Disabled
disabled prop으로 Textarea를 비활성화할 수 있어요.
<template>
<UTextarea disabled placeholder="Type something..." />
</template>
API
Props
/**
* Props for the Textarea component
*/
interface TextareaProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
id?: string | undefined;
name?: string | undefined;
/**
* The placeholder text when the textarea is empty.
*/
placeholder?: string | undefined;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'outline'
*/
variant?: "outline" | "soft" | "subtle" | "ghost" | "none" | undefined;
/**
* @default 'md'
*/
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
required?: boolean | undefined;
autofocus?: boolean | undefined;
/**
* @default 0
*/
autofocusDelay?: number | undefined;
autoresize?: boolean | undefined;
/**
* @default 0
*/
autoresizeDelay?: number | undefined;
disabled?: boolean | undefined;
/**
* @default 3
*/
rows?: number | undefined;
/**
* @default 0
*/
maxrows?: number | undefined;
/**
* Highlight the ring color like a focus state.
*/
highlight?: boolean | undefined;
/**
* Keep the mobile text size on all breakpoints.
*/
fixed?: boolean | undefined;
defaultValue?: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod> | undefined;
modelValue?: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod> | undefined;
modelModifiers?: Mod | undefined;
ui?: { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; } | undefined;
/**
* Display an icon based on the `leading` and `trailing` props.
*/
icon?: any;
/**
* Display an avatar on the left side.
*/
avatar?: AvatarProps | undefined;
/**
* When `true`, the icon will be displayed on the left side.
*/
leading?: boolean | undefined;
/**
* Display an icon on the left side.
*/
leadingIcon?: any;
/**
* When `true`, the icon will be displayed on the right side.
*/
trailing?: boolean | undefined;
/**
* Display an icon on the right side.
*/
trailingIcon?: any;
/**
* When `true`, the loading icon will be displayed.
*/
loading?: boolean | undefined;
/**
* The icon when the `loading` prop is `true`.
* @default appConfig.ui.icons.loading
*/
loadingIcon?: any;
autocomplete?: string | undefined;
cols?: string | number | undefined;
dirname?: string | undefined;
form?: string | undefined;
maxlength?: string | number | undefined;
minlength?: string | number | undefined;
readonly?: false | true | "true" | "false" | undefined;
wrap?: string | undefined;
}
[!NOTE] 참고: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#attributes
이 컴포넌트는 네이티브
<textarea>HTML 속성도 모두 지원해요.
Slots
/**
* Slots for the Textarea component
*/
interface TextareaSlots {
leading(): any;
default(): any;
trailing(): any;
}
Emits
/**
* Emitted events for the Textarea component
*/
interface TextareaEmits {
update:modelValue: (payload: [value: _Number<_Optional<_Nullable<T, Mod>, Mod>, Mod>]) => void;
blur: (payload: [event: FocusEvent]) => void;
change: (payload: [event: Event]) => void;
}
Expose
템플릿 ref로 컴포넌트에 접근할 때 다음을 사용할 수 있어요:
| Name | Type |
|---|---|
textareaRef |
Ref<HTMLTextAreaElement | null> |
autoResize |
() => void |
테마
export default defineAppConfig({
ui: {
textarea: {
slots: {
root: 'relative inline-flex items-center',
base: [
'w-full rounded-md border-0 appearance-none placeholder:text-dimmed disabled:cursor-not-allowed disabled:opacity-75',
'transition-colors'
],
leading: 'absolute start-0 flex items-start',
leadingIcon: 'shrink-0 text-dimmed',
leadingAvatar: 'shrink-0',
leadingAvatarSize: '',
trailing: 'absolute end-0 flex items-start',
trailingIcon: 'shrink-0 text-dimmed'
},
variants: {
fieldGroup: {
horizontal: {
root: 'group has-focus-visible:z-[1]',
base: 'group-not-only:group-first:rounded-e-none group-not-only:group-last:rounded-s-none group-not-last:group-not-first:rounded-none'
},
vertical: {
root: 'group has-focus-visible:z-[1]',
base: 'group-not-only:group-first:rounded-b-none group-not-only:group-last:rounded-t-none group-not-last:group-not-first:rounded-none'
}
},
size: {
xs: {
base: 'px-2 py-1 text-sm/4 gap-1',
leading: 'ps-2 inset-y-1',
trailing: 'pe-2 inset-y-1',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4'
},
sm: {
base: 'px-2.5 py-1.5 text-sm/4 gap-1.5',
leading: 'ps-2.5 inset-y-1.5',
trailing: 'pe-2.5 inset-y-1.5',
leadingIcon: 'size-4',
leadingAvatarSize: '3xs',
trailingIcon: 'size-4'
},
md: {
base: 'px-2.5 py-1.5 text-base/5 gap-1.5',
leading: 'ps-2.5 inset-y-1.5',
trailing: 'pe-2.5 inset-y-1.5',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5'
},
lg: {
base: 'px-3 py-2 text-base/5 gap-2',
leading: 'ps-3 inset-y-2',
trailing: 'pe-3 inset-y-2',
leadingIcon: 'size-5',
leadingAvatarSize: '2xs',
trailingIcon: 'size-5'
},
xl: {
base: 'px-3 py-2 text-base gap-2',
leading: 'ps-3 inset-y-2',
trailing: 'pe-3 inset-y-2',
leadingIcon: 'size-6',
leadingAvatarSize: 'xs',
trailingIcon: 'size-6'
}
},
variant: {
outline: 'text-highlighted bg-default ring ring-inset ring-accented',
soft: 'text-highlighted bg-elevated/50 hover:bg-elevated focus:bg-elevated disabled:bg-elevated/50',
subtle: 'text-highlighted bg-elevated ring ring-inset ring-accented',
ghost: 'text-highlighted bg-transparent hover:bg-elevated focus:bg-elevated disabled:bg-transparent dark:disabled:bg-transparent',
none: 'text-highlighted bg-transparent focus:outline-none'
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
fixed: {
false: ''
},
type: {
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none'
},
autoresize: {
true: {
base: 'resize-none'
}
}
},
compoundVariants: [
{
color: 'primary',
variant: [
'outline',
'subtle'
],
class: 'outline-primary/25 focus-visible:outline-3 focus-visible:ring-primary'
},
{
color: 'secondary',
variant: [
'outline',
'subtle'
],
class: 'outline-secondary/25 focus-visible:outline-3 focus-visible:ring-secondary'
},
{
color: 'success',
variant: [
'outline',
'subtle'
],
class: 'outline-success/25 focus-visible:outline-3 focus-visible:ring-success'
},
{
color: 'info',
variant: [
'outline',
'subtle'
],
class: 'outline-info/25 focus-visible:outline-3 focus-visible:ring-info'
},
{
color: 'warning',
variant: [
'outline',
'subtle'
],
class: 'outline-warning/25 focus-visible:outline-3 focus-visible:ring-warning'
},
{
color: 'error',
variant: [
'outline',
'subtle'
],
class: 'outline-error/25 focus-visible:outline-3 focus-visible:ring-error'
},
{
color: 'primary',
variant: [
'soft',
'ghost'
],
class: 'outline-primary/25 focus-visible:outline-3'
},
{
color: 'secondary',
variant: [
'soft',
'ghost'
],
class: 'outline-secondary/25 focus-visible:outline-3'
},
{
color: 'success',
variant: [
'soft',
'ghost'
],
class: 'outline-success/25 focus-visible:outline-3'
},
{
color: 'info',
variant: [
'soft',
'ghost'
],
class: 'outline-info/25 focus-visible:outline-3'
},
{
color: 'warning',
variant: [
'soft',
'ghost'
],
class: 'outline-warning/25 focus-visible:outline-3'
},
{
color: 'error',
variant: [
'soft',
'ghost'
],
class: 'outline-error/25 focus-visible:outline-3'
},
{
color: 'primary',
highlight: true,
class: 'ring ring-inset ring-primary'
},
{
color: 'secondary',
highlight: true,
class: 'ring ring-inset ring-secondary'
},
{
color: 'success',
highlight: true,
class: 'ring ring-inset ring-success'
},
{
color: 'info',
highlight: true,
class: 'ring ring-inset ring-info'
},
{
color: 'warning',
highlight: true,
class: 'ring ring-inset ring-warning'
},
{
color: 'error',
highlight: true,
class: 'ring ring-inset ring-error'
},
{
color: 'neutral',
variant: [
'outline',
'subtle'
],
class: 'outline-inverted/25 focus-visible:outline-3 focus-visible:ring-inverted'
},
{
color: 'neutral',
variant: [
'soft',
'ghost'
],
class: 'outline-inverted/25 focus-visible:outline-3'
},
{
color: 'neutral',
highlight: true,
class: 'ring ring-inset ring-inverted'
},
{
leading: true,
size: 'xs',
class: 'ps-7'
},
{
leading: true,
size: 'sm',
class: 'ps-8'
},
{
leading: true,
size: 'md',
class: 'ps-9'
},
{
leading: true,
size: 'lg',
class: 'ps-10'
},
{
leading: true,
size: 'xl',
class: 'ps-11'
},
{
trailing: true,
size: 'xs',
class: 'pe-7'
},
{
trailing: true,
size: 'sm',
class: 'pe-8'
},
{
trailing: true,
size: 'md',
class: 'pe-9'
},
{
trailing: true,
size: 'lg',
class: 'pe-10'
},
{
trailing: true,
size: 'xl',
class: 'pe-11'
},
{
loading: true,
leading: true,
class: {
leadingIcon: 'animate-spin'
}
},
{
loading: true,
leading: false,
trailing: true,
class: {
trailingIcon: 'animate-spin'
}
},
{
fixed: false,
size: 'xs',
class: 'md:text-xs'
},
{
fixed: false,
size: 'sm',
class: 'md:text-xs'
},
{
fixed: false,
size: 'md',
class: 'md:text-sm'
},
{
fixed: false,
size: 'lg',
class: 'md:text-sm'
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
})
변경 기록
사이트맵
전체 페이지 목록은 사이트맵에서 확인할 수 있어요.