Skip to content

Textarea

🌏 Translated with the assistance of DeepSeek and ChatGPT

A very, very, very, very, very large amount of text can be entered here.

Basic Usage

You can enter multiple lines of text here. Pass in modelValue to enable controlled mode. If not passed or set to undefined, it will be uncontrolled mode, in which case you can use the defaultValue property as the default value.

<template>
	<px-space direction="vertical">
		<px-textarea placeholder="Please input" v-model="input"></px-textarea>
		<px-textarea placeholder="Please input" default-value="!!!"></px-textarea>
	</px-space>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const input = ref('Excalibur')
</script>

<style lang="css" scoped>
.px-textarea {
	width: 320px;
}
</style>

Rows

The rows property controls the default number of rows. minRows and maxRows set the minimum and maximum number of rows. When autoResize is true, the height will adjust automatically.

<template>
	<px-space direction="vertical">
		<px-textarea placeholder="Please input" v-model="input" :rows="4"></px-textarea>
		<px-textarea
			placeholder="Please input"
			v-model="input"
			:rows="4"
			:min-rows="2"
			:max-rows="6"
		></px-textarea>
		<px-textarea
			placeholder="Please input"
			v-model="input"
			auto-resize
			:min-rows="2"
			:max-rows="6"
			:rows="4"
		></px-textarea>
	</px-space>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const input = ref('Berserker!')
</script>

<style lang="css" scoped>
.px-textarea {
	width: 320px;
}
</style>

Manual Resize

The resize property controls whether the manual resize handle is shown. It is shown by default.

<template>
	<px-space direction="vertical">
		<px-textarea placeholder="Please input" v-model="input"></px-textarea>
		<px-textarea placeholder="Please input" v-model="input" :resize="false"></px-textarea>
	</px-space>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const input = ref('Text')
</script>

<style lang="css" scoped>
.px-textarea {
	width: 320px;
}
</style>

More Options

Textarea also has some features of the Input component.

Disabled, Readonly, Loading & Clearable

Size

Count

0
0 / 255

Status

Expose

<template>
	<px-space direction="vertical">
		<h4>Disabled, Readonly, Loading & Clearable</h4>
		<px-space>
			<px-textarea placeholder="Please input text" disabled></px-textarea>
			<px-textarea placeholder="Please input text" readonly></px-textarea>
			<px-textarea placeholder="Please input text" loading></px-textarea>
			<px-textarea placeholder="Please input text" clearable></px-textarea>
		</px-space>
		<h4>Size</h4>
		<px-space>
			<px-textarea placeholder="Please input text" size="small"></px-textarea>
			<px-textarea placeholder="Please input text"></px-textarea>
			<px-textarea placeholder="Please input text" size="large"></px-textarea>
		</px-space>
		<h4>Count</h4>
		<px-space>
			<px-textarea placeholder="Please input text" show-count> </px-textarea>
			<px-textarea placeholder="Please input text" show-count :max-length="255"> </px-textarea>
		</px-space>
		<h4>Status</h4>
		<px-space>
			<px-textarea placeholder="Please input text"> </px-textarea>
			<px-textarea placeholder="Please input text" status="success"> </px-textarea>
			<px-textarea placeholder="Please input text" status="warning"> </px-textarea>
			<px-textarea placeholder="Please input text" status="error"> </px-textarea>
		</px-space>
		<h4>Expose</h4>
		<px-space direction="vertical">
			<px-space>
				<px-button theme="info" @click="focusHandler">Focus</px-button>
				<px-button theme="info" @click="blurHandler">Blur</px-button>
				<px-button theme="info" @click="selectHandler">Select</px-button>
				<px-button theme="warning" @click="clearHandler">Clear</px-button>
			</px-space>
			<px-textarea placeholder="Please input" ref="textareaRef"></px-textarea>
		</px-space>
	</px-space>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { Textarea } from '@pixelium/web-vue'

// If on-demand import
// import { Textarea } from '@pixelium/web-vue/es'

const textareaRef = ref<InstanceType<typeof Textarea>>(null)

const focusHandler = () => {
	textareaRef.value?.focus()
}
const blurHandler = () => {
	textareaRef.value?.blur()
}
const clearHandler = () => {
	textareaRef.value?.clear()
}
const selectHandler = () => {
	textareaRef.value?.select()
}
</script>

<style lang="css" scoped>
.px-textarea {
	width: 320px;
}
</style>

API

TextareaProps

AttributeTypeOptionalDefaultDescriptionVersion
modelValuestring | nullTrueValue of the textarea (controlled mode), supports v-model.0.0.2
defaultValuestring | nullTrueDefault value of the textarea (uncontrolled mode).0.0.2
rowsnumberTrueDefault number of rows.0.0.2
minRowsnumberTrue1Minimum number of rows.0.0.2
maxRowsnumberTrueInfinityMaximum number of rows.0.0.2
autoResizebooleanTruefalseWhether automatic resizing is allowed.0.0.2
resizebooleanTruetrueWhether manual resizing is allowed.0.0.2
placeholderstringTruePlaceholder text.0.0.2
disabledbooleanTruefalseDisabled state.0.0.2
readonlybooleanTruefalseRead-only state.0.0.2
clearablebooleanTruefalseWhether to show the clear button.0.0.2
loadingbooleanTruefalseWhether to show the loading state.0.0.2
size'medium' | 'large' | 'small'True'medium'Input box size.0.0.2
maxLengthnumberTrueMaximum input length.0.0.2
showCountbooleanTruefalseWhether to show character count.0.0.2
countGraphemes(value: string) => numberTrueCustom function for counting characters. If only countGraphemes is provided without sliceGraphemes, the maxLength limit will not take effect.0.0.2
sliceGraphemes(value: string, limit: number) => stringTrueCustom function for slicing the string.0.0.2
status'success' | 'warning' | 'error' | 'normal'True'normal'Form validation status.0.0.2
autofocusbooleanTruefalseNative <input> autofocus attribute.0.0.2

TextareaEvents

EventParameterDescriptionVersion
inputvalue: string, e: EventCallback when the textarea receives input.0.0.2
update:modelValuevalue: stringCallback to update modelValue.0.0.2
changevalue: string, e: Event | undefinedCallback when the input value changes.0.0.2
clearvalue: stringCallback when the clear button is clicked and the content is cleared.0.0.2
blure: FocusEventCallback when the textarea loses focus.0.0.2
focuse: FocusEventCallback when the textarea is focused.0.0.2

TextareaSlots

SlotParameterDescriptionVersion
countinputValue: number, currentLength: number, maxLength: numberSlot for displaying character count.0.0.2

TextareaExpose

AttributeTypeOptionalDefaultDescriptionVersion
focus() => voidFalseFocus the current textarea.0.0.2
blur() => voidFalseRemove focus from the current textarea.0.0.2
clear() => voidFalseClear the current textarea.0.0.2
select() => voidFalseSelect the content of the current textarea.0.0.2