Skip to content

TextInput ​

The TextInput component provides a configurable text input field for single-line and multi-line entry. It supports validation, styling, and keyboard navigation.

Basic Usage ​

vue
<template>
  <TextInput v-model="textValue" placeholder="Enter text..." />
</template>

<script setup>
import { ref } from 'vue';
import { TextInput } from 'vuetty';

const textValue = ref('');
</script>

Props ​

NameTypeDefaultDescription
modelValuestring''The input value (v-model binding)
multilinebooleanfalseEnable multi-line input mode
rowsnumber3Number of visible rows in multi-line mode
minRowsnumber1Minimum rows in auto-resize mode
maxRowsnumberundefinedMaximum rows in auto-resize mode
autoResizebooleantrueAutomatically adjust height based on content
widthnumber | stringnullFixed width in characters (auto if not set)
wrapLinesbooleantrueEnable line wrapping for long text
labelstring''Label displayed above the input
placeholderstring''Placeholder text when input is empty
hintstring | boolean'default'Hint text shown when focused. Use 'default' for standard hints, false to disable, or pass custom text
colorstring-Text color (chalk color names)
borderColorstring-Border color when not focused or in error
bgstring-Background color
focusColorstring'cyan'Border color when focused
errorColorstring'red'Border color when validation fails
boldbooleanfalseBold text
italicbooleanfalseItalic text
dimbooleanfalseDimmed text
patternRegExp-Validation regex pattern
requiredbooleanfalseMark field as required
maxLengthnumber-Maximum character length
pasteLongThresholdnumber80Character length threshold for long paste handling. Pasted content exceeding this length is inserted as a placeholder instead of raw text
disabledbooleanfalseDisable input
readonlybooleanfalseMake input read-only

Layout Props (Box Props) ​

NameTypeDefaultDescription
flexnumber | stringnullFlex shorthand when inside a flex container
flexGrownumbernullFlex grow factor
flexShrinknumbernullFlex shrink factor
flexBasisnumber | stringnullFlex basis
alignSelfstringnullSelf alignment: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'
widthnumber | stringnullWidth (chars or %)
heightnumber | stringnullHeight (rows)
minWidthnumbernullMinimum width
maxWidthnumbernullMaximum width
minHeightnumbernullMinimum height
maxHeightnumbernullMaximum height
paddingnumbernullPadding
paddingLeftnumbernullLeft padding
paddingRightnumbernullRight padding
paddingTopnumbernullTop padding
paddingBottomnumbernullBottom padding
marginnumbernullMargin
marginLeftnumbernullLeft margin
marginRightnumbernullRight margin
marginTopnumbernullTop margin
marginBottomnumbernullBottom margin

Input Modes ​

TextInput supports both single-line and multi-line modes:

vue
<template>
  <Col :gap="1">
    <!-- Single-line input -->
    <TextInput v-model="username" placeholder="Enter username" />

    <!-- Multi-line input -->
    <TextInput
      v-model="description"
      multiline
      :rows="5"
      placeholder="Enter description..."
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const username = ref('');
const description = ref('');
</script>

In multi-line mode, Enter submits the value (emits change), while Shift+Enter inserts a newline. Ctrl+Enter submits from either mode. The ↑/↓ arrow keys move the cursor between lines.

Validation ​

TextInput provides built-in validation features:

vue
<template>
  <Col :gap="1">
    <!-- Required field -->
    <TextInput
      v-model="email"
      required
      placeholder="Email is required"
    />

    <!-- Pattern validation -->
    <TextInput
      v-model="validatedEmail"
      :pattern="/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/"
      placeholder="Enter valid email"
    />

    <!-- Max length -->
    <TextInput
      v-model="username"
      :maxLength="20"
      placeholder="Max 20 characters"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const email = ref('');
const validatedEmail = ref('');
const username = ref('');
</script>

Styling ​

Customize input appearance with colors and text effects:

vue
<template>
  <Col :gap="1">
    <!-- Custom colors -->
    <TextInput
      v-model="text1"
      color="green"
      borderColor="white"
      focusColor="magenta"
      placeholder="Custom colors"
    />

    <!-- Text styling -->
    <TextInput
      v-model="text2"
      bold
      placeholder="Bold text input"
    />

    <!-- Combined styling -->
    <TextInput
      v-model="text3"
      bold
      italic
      color="cyan"
      placeholder="Bold italic cyan"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const text1 = ref('');
const text2 = ref('');
const text3 = ref('');
</script>

Hints ​

Control hint text displayed when focused (hint text uses the input text color with dim styling):

vue
<template>
  <Col :gap="1">
    <!-- Default hint (automatic based on input type) -->
    <TextInput v-model="text1" placeholder="Default hint" />

    <!-- Custom hint -->
    <TextInput
      v-model="text2"
      hint="Press Enter to confirm"
      placeholder="Custom hint"
    />

    <!-- No hint -->
    <TextInput
      v-model="text3"
      :hint="false"
      placeholder="No hint"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const text1 = ref('');
const text2 = ref('');
const text3 = ref('');
</script>

TIP

Single-line inputs show "Enter to submit" by default, while multi-line inputs show "Enter to submit, Shift+Enter for new line".

Width Control ​

Control input width with the width prop:

vue
<template>
  <Col :gap="1">
    <!-- Fixed width -->
    <TextInput
      v-model="text1"
      :width="30"
      placeholder="Fixed width (30 chars)"
    />

    <!-- Auto width (default) -->
    <TextInput
      v-model="text2"
      placeholder="Auto width based on content"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const text1 = ref('');
const text2 = ref('');
</script>

Events ​

EventPayloadDescription
update:modelValuestringEmitted on every edit (v-model)
changestringEmitted when the user submits the value: Enter (single-line), Enter/Ctrl+Enter (multi-line)
focus-Emitted when the input receives keyboard focus
blur-Emitted when the input loses keyboard focus
validate{ valid, errors }Emitted after each edit with the validation result
vue
<template>
  <Col :gap="1">
    <!-- Change event -->
    <TextInput
      v-model="text1"
      @change="onChange"
      placeholder="Type and press Enter"
    />

    <!-- Focus and blur events -->
    <TextInput
      v-model="text2"
      @focus="onFocus"
      @blur="onBlur"
      placeholder="Focus and blur events"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const text1 = ref('');
const text2 = ref('');

const onChange = (value) => {
  console.log('Input submitted:', value);
};

const onFocus = () => {
  console.log('Input focused');
};

const onBlur = () => {
  console.log('Input blurred');
};
</script>

Common Patterns ​

Form Input with Validation ​

vue
<template>
  <Col :gap="1">
    <TextInput
      v-model="username"
      label="Username"
      required
      placeholder="Enter username"
    />
    <TextInput
      v-model="email"
      label="Email"
      :pattern="/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/"
      placeholder="Enter email"
    />
    <TextInput
      v-model="notes"
      multiline
      :rows="5"
      label="Notes"
      placeholder="Enter your notes here..."
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, TextInput } from 'vuetty';

const username = ref('');
const email = ref('');
const notes = ref('');
</script>

Search Field ​

vue
<template>
  <TextInput
    v-model="searchQuery"
    placeholder="Search..."
    @change="onSearch"
  />
</template>

<script setup>
import { ref } from 'vue';
import { TextInput } from 'vuetty';

const searchQuery = ref('');

const onSearch = (query) => {
  console.log('Searching for:', query);
};
</script>

Usage with Other Components ​

TextInput integrates seamlessly with layout components:

vue
<template>
  <Col :gap="2">
    <!-- Input inside a box -->
    <Box :padding="1" color="cyan">
      <TextInput
        v-model="text"
        placeholder="Input inside a box"
      />
    </Box>

    <!-- Multiple inputs in a row -->
    <Row :gap="2">
      <Col :flex="1">
        <TextInput
          v-model="firstName"
          placeholder="First Name"
        />
      </Col>
      <Col :flex="1">
        <TextInput
          v-model="lastName"
          placeholder="Last Name"
        />
      </Col>
    </Row>
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Box, Row, Col, TextInput } from 'vuetty';

const text = ref('');
const firstName = ref('');
const lastName = ref('');
</script>

Released under the MIT License.