Skip to content

Text Input ​

The go-to component for collecting short text from users -- names, emails, search queries, and more. It handles labels, validation, prefix/suffix decorations, and can even stretch into a textarea when you need longer content.

ts
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

Basic Usage ​

Wire up a text input with v-model and wrap it in a CoarFormField to add a label, placeholder, and optional hint to guide the user.

Choose a unique username
Value: empty
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 320px;">
    <CoarFormField label="Username" hint="Choose a unique username">
      <CoarTextInput
        v-model="value"
        placeholder="Enter your username"
      />
    </CoarFormField>
    <span style="font-size: 13px; color: #64748b;">Value: {{ value || 'empty' }}</span>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

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

Validation States ​

Add required to both CoarFormField (for the asterisk) and the input (for the HTML attribute). Pass an error string to CoarFormField to surface validation feedback beneath the input.

Required field
Please enter a valid email address
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 320px;">
    <CoarFormField label="Email" hint="Required field" required>
      <CoarTextInput
        v-model="email"
        placeholder="your@email.com"
        :required="true"
      />
    </CoarFormField>
    <CoarFormField label="Email" error="Please enter a valid email address">
      <CoarTextInput
        value="invalid-email"
      />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

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

Disabled & Readonly ​

Use disabled when the field should be completely non-interactive, and readonly when users should be able to see and copy the value but not change it.

vue
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 320px;">
    <CoarFormField label="Disabled">
      <CoarTextInput value="Cannot edit" :disabled="true" />
    </CoarFormField>
    <CoarFormField label="Readonly">
      <CoarTextInput value="View only" :readonly="true" />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';
</script>

Prefix & Suffix ​

Prefix and suffix slots help users understand the expected format -- think currency symbols, units, or domain names.

https://
EUR
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 320px;">
    <CoarFormField label="Website">
      <CoarTextInput v-model="website" placeholder="example.com" prefix="https://" />
    </CoarFormField>
    <CoarFormField label="Price">
      <CoarTextInput v-model="price" placeholder="0.00" suffix="EUR" />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

const website = ref('');
const price = ref('');
</script>

Clear Button ​

When clearable is enabled, a small X button appears on hover or focus so users can quickly reset the field. It's off by default — set clearable to opt in.

Value: empty
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 320px;">
    <CoarFormField label="Search">
      <CoarTextInput
        v-model="search"
        placeholder="Type to search..."
        :clearable="true"
      />
    </CoarFormField>
    <span style="font-size: 13px; color: #64748b;">Value: {{ search || 'empty' }}</span>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

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

Sizes ​

Four sizes let you match the input to its surroundings -- compact toolbars, standard forms, or spacious layouts.

vue
<template>
  <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px;">
    <CoarFormField label="Extra Small">
      <CoarTextInput size="xs" placeholder="27px" />
    </CoarFormField>
    <CoarFormField label="Small">
      <CoarTextInput size="s" placeholder="32px" />
    </CoarFormField>
    <CoarFormField label="Medium">
      <CoarTextInput size="m" placeholder="40px" />
    </CoarFormField>
    <CoarFormField label="Large">
      <CoarTextInput size="l" placeholder="48px" />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';
</script>

Multiline (Textarea) ​

Set rows to 2 or more and the input switches to a textarea, perfect for descriptions, notes, or any free-form content.

Max 500 characters
vue
<template>
  <div style="display: flex; flex-direction: column; gap: 16px; max-width: 400px;">
    <CoarFormField label="Bio" hint="Max 500 characters">
      <CoarTextInput
        v-model="bio"
        placeholder="Tell us about yourself..."
        :rows="4"
      />
    </CoarFormField>
    <CoarFormField label="6 Rows">
      <CoarTextInput :rows="6" placeholder="Taller textarea..." />
    </CoarFormField>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { CoarTextInput, CoarFormField } from '@cocoar/vue-ui';

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

Accessibility ​

Keyboard Navigation ​

KeyAction
TabMove focus to input
Shift + TabMove focus backward
EscapeClear input (when clearable)

INFO

Labels are automatically associated with their inputs. The required asterisk is announced by screen readers.

Screen Reader Support ​

  • Label text announces on focus
  • Required state properly communicated
  • Error messages are linked via aria-describedby
  • Hint text is accessible to assistive technology

API ​

Props ​

PropTypeDefaultDescription
v-modelstring''Current input value (two-way binding)
placeholderstring''Placeholder text when empty
prefixstring''Prefix text before the input
suffixstring''Suffix text after the input
size'xs' | 's' | 'm' | 'l''m'Input size
rowsnumber1Rows >= 2 enables textarea mode
clearablebooleanfalseShow clear button when input has value
errorbooleanfalseError state (auto-injected from CoarFormField)
disabledbooleanfalseDisable the input
readonlybooleanfalseMake read-only
requiredbooleanfalseHTML required attribute

TIP

Label, hint, and error are provided by CoarFormField. Wrap inputs in a CoarFormField to add these features.

i18n Keys ​

These keys can be translated via @cocoar/vue-localization.

KeyDefault (English)Used as
coar.ui.textInput.clear'Clear'Clear button aria-label

Released under the Apache-2.0 License.