Skip to content

Input

A text input component for receiving user input.

NameCategoryDescriptionTypeDefault
type? StyleInput type, supports native HTML input types'text' | 'password' | 'textarea' | 'date' | 'time' | 'url' | ...'text'
color? StyleInput color, accepts preset theme colors or custom hex values'primary' | 'success' | 'warning' | 'danger' | 'info' | string
ghost? StyleWhether to use ghost style (no border/shadow at rest, visible on hover)booleanfalse
size? SizeSize'large' | 'default' | 'small''default'
disabled? StateWhether disabledbooleanfalse
readonly? StateWhether readonlybooleanfalse
clearable? BehaviorWhether clearablebooleanfalse
show-password? BehaviorWhether to show password togglebooleanfalse
autocomplete? BehaviorNative autocomplete attributestring'off'
autofocus? BehaviorWhether to auto focusbooleanfalse
form? BehaviorNative form attribute, associates with a formstring
model-value / v-model? ContentBinding valuestring
placeholder? ContentPlaceholderstring
prefix-icon? ContentPrefix iconstring
suffix-icon? ContentSuffix iconstring
input? EventTriggered on input(value: string) => void
change? EventTriggered when value changes(value: string) => void
focus? EventTriggered on focus(event: FocusEvent) => void
blur? EventTriggered on blur(event: FocusEvent) => void
clear? EventTriggered on clear() => void
prefix? SlotPrefix content
suffix? SlotSuffix content
prepend? SlotPrepend content
append? SlotAppend content
ref? ExposeInput HTML elementRef<HTMLInputElement>
focus? ExposeFocus the input() => void
blur? ExposeBlur the input() => void
clear? ExposeClear the input() => void
select? ExposeSelect the text in the input() => void

Basic Usage

Basic usage of the input component.

<template>
  <div class="demo-input">
    <px-input v-model="input1" placeholder="请输入内容" />
    <px-input v-model="input2" placeholder="禁用状态" disabled />
  </div>
</template>

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

const input1 = ref('');
const input2 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Input Colors

Use the color prop to apply preset theme colors to the input border and shadow.

<template>
  <div class="demo-input">
    <px-input v-model="v1" color="primary" placeholder="Primary" />
    <px-input v-model="v2" color="success" placeholder="Success" />
    <px-input v-model="v3" color="warning" placeholder="Warning" />
    <px-input v-model="v4" color="danger" placeholder="Danger" />
    <px-input v-model="v5" color="info" placeholder="Info" />
  </div>
</template>

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

const v1 = ref('');
const v2 = ref('');
const v3 = ref('');
const v4 = ref('');
const v5 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Custom Colors

Pass any hex color string to the color prop for fully custom colored inputs. Combine with ghost for transparent-at-rest variants.

<template>
  <div class="demo-input">
    <h4>Default</h4>
    <px-input v-model="v1" color="#626aef" placeholder="Indigo #626aef" />
    <px-input v-model="v2" color="#ff6b9d" placeholder="Pink #ff6b9d" />
    <px-input v-model="v3" color="#36cfc9" placeholder="Teal #36cfc9" />

    <h4>Ghost</h4>
    <px-input v-model="v4" color="#626aef" ghost placeholder="Indigo ghost" />
    <px-input v-model="v5" color="#ff6b9d" ghost placeholder="Pink ghost" />
    <px-input v-model="v6" color="#36cfc9" ghost placeholder="Teal ghost" />
  </div>
</template>

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

const v1 = ref('');
const v2 = ref('');
const v3 = ref('');
const v4 = ref('');
const v5 = ref('');
const v6 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
.demo-input h4 {
  margin: 8px 0 0;
}
</style>

Ghost Style

Use the ghost prop to create borderless inputs that reveal their border and shadow on hover/focus. Works with both preset and custom colors.

<template>
  <div class="demo-input">
    <px-input v-model="v1" ghost placeholder="Ghost default" />
    <px-input v-model="v2" ghost color="primary" placeholder="Ghost primary" />
    <px-input v-model="v3" ghost color="success" placeholder="Ghost success" />
    <px-input v-model="v4" ghost color="danger" placeholder="Ghost danger" />
  </div>
</template>

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

const v1 = ref('');
const v2 = ref('');
const v3 = ref('');
const v4 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Different Sizes

Use size property to set the input size.

<template>
  <div class="demo-input">
    <px-input v-model="input1" size="large" placeholder="大尺寸" />
    <px-input v-model="input2" placeholder="默认尺寸" />
    <px-input v-model="input3" size="small" placeholder="小尺寸" />
  </div>
</template>

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

const input1 = ref('');
const input2 = ref('');
const input3 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Disabled & Readonly

Use disabled and readonly properties to control the input state.

<template>
  <div class="demo-input">
    <px-input v-model="input1" placeholder="Disabled input" disabled />
    <px-input v-model="input2" placeholder="Readonly input" readonly />
  </div>
</template>

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

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

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Clearable

Use clearable property to enable the clear button.

<template>
  <div class="demo-input">
    <px-input v-model="input" placeholder="可清空" clearable />
  </div>
</template>

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

const input = ref('Hello World');
</script>

<style scoped>
.demo-input {
  max-width: 300px;
}
</style>

Password

Use type="password" and show-password properties to create a password input.

<template>
  <form class="demo-input" @submit.prevent>
    <px-input v-model="password" type="password" placeholder="请输入密码" show-password />
  </form>
</template>

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

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

<style scoped>
.demo-input {
  max-width: 300px;
}
</style>

Prefix & Suffix

Use prefix-icon / suffix-icon properties or prefix / suffix slots to add content before or after the input.

<template>
  <div class="demo-input">
    <px-input v-model="input1" placeholder="Prefix icon" prefix-icon="search" />
    <px-input v-model="input2" placeholder="Suffix icon" suffix-icon="edit" />
    <px-input v-model="input3" placeholder="With slot prefix">
      <template #prefix>
        <px-icon icon="coin" />
      </template>
    </px-input>
    <px-input v-model="input4" placeholder="With slot suffix">
      <template #suffix>
        <px-icon icon="mail" />
      </template>
    </px-input>
  </div>
</template>

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

const input1 = ref('');
const input2 = ref('');
const input3 = ref('');
const input4 = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>

Native Types

The type prop supports all native HTML input types. Here are examples with date, time, and url.

<template>
  <div class="demo-input">
    <px-input v-model="date" type="date" placeholder="Select date">
      <template #prefix>
        <px-icon icon="calendar" />
      </template>
    </px-input>
    <px-input v-model="time" type="time" placeholder="Select time">
      <template #prefix>
        <px-icon icon="clock" />
      </template>
    </px-input>
    <px-input v-model="url" type="url" placeholder="https://example.com">
      <template #prefix>
        <px-icon icon="link" />
      </template>
    </px-input>
  </div>
</template>

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

const date = ref('');
const time = ref('');
const url = ref('');
</script>

<style scoped>
.demo-input {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 300px;
}
</style>