Preview Updated 2026-05-10

Input

Single-line input — 3 variants, 3 sizes, error state, clearable, prefix/suffix.

Basic usage

v-model / value + onChange binds directly to a string. placeholder matches the native input.

已输入:(空)

<script setup lang="ts">
import { ref } from 'vue';
import { CfInput } from '@chufix-design/vue';

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

<template>
<CfInput v-model="name" placeholder="Enter username" />
</template>
import { useState } from 'react';
import { CfInput } from '@chufix-design/react';

export default function Demo() {
const [name, setName] = useState('');
return (
  <CfInput
    value={name}
    onChange={(e) => setName(e.target.value)}
    placeholder="Enter username"
  />
);
}

Variants

Three variants offer different border / background intensities. filled fits dense forms; ghost avoids double borders when wrapped in a container that already has one.

<CfInput variant="outline" placeholder="outline · default" />
<CfInput variant="filled" placeholder="filled · gray fill" />
<CfInput variant="ghost" placeholder="ghost · borderless, appears on focus" />
<CfInput variant="outline" placeholder="outline · default" />
<CfInput variant="filled" placeholder="filled · gray fill" />
<CfInput variant="ghost" placeholder="ghost · borderless, appears on focus" />

Sizes

<CfInput size="sm" placeholder="Small" />
<CfInput size="md" placeholder="Medium" />
<CfInput size="lg" placeholder="Large" />
<CfInput size="sm" placeholder="Small" />
<CfInput size="md" placeholder="Medium" />
<CfInput size="lg" placeholder="Large" />

States

clearable shows the clear button only when there is a value; error switches to a danger border + ring; disabled / readonly match the native input.

<script setup lang="ts">
import { ref } from 'vue';
import { CfInput } from '@chufix-design/vue';

const email = ref('not-an-email');
const valid = (s: string) => /.+@.+\..+/.test(s);
</script>

<template>
<CfInput v-model="search" clearable placeholder="Clearable (× appears once typed)" />
<CfInput
  v-model="email"
  :error="!valid(email)"
  placeholder="Error state: invalid email"
/>
<CfInput placeholder="Disabled" disabled />
<CfInput placeholder="Readonly" readonly model-value="readonly content" />
</template>
import { useState } from 'react';
import { CfInput } from '@chufix-design/react';

export default function Demo() {
const [email, setEmail] = useState('not-an-email');
const valid = /.+@.+\..+/.test(email);

return (
  <>
    <CfInput clearable placeholder="Clearable (× appears once typed)" />
    <CfInput
      value={email}
      onChange={(e) => setEmail(e.target.value)}
      error={!valid}
      placeholder="Error state: invalid email"
    />
    <CfInput placeholder="Disabled" disabled />
    <CfInput placeholder="Readonly" readOnly defaultValue="readonly content" />
  </>
);
}

Prefix and suffix

Use named slots (Vue) / prefix & suffix props (React) to place an icon or fixed text. clearable and suffix are mutually exclusive (the clear button shows when there is a value).

<CfInput v-model="url" placeholder="example">
<template #prefix>https://</template>
<template #suffix>.com</template>
</CfInput>

<CfInput v-model="search" clearable placeholder="Search…">
<template #prefix>
  <SearchIcon />
</template>
</CfInput>
<CfInput
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="example"
prefix={<>https://</>}
suffix={<>.com</>}
/>

<CfInput
value={search}
onChange={(e) => setSearch(e.target.value)}
clearable
placeholder="Search…"
prefix={<SearchIcon />}
/>

API

PropTypeDefaultDescription
modelValuestring | numberVue v-model value
valuestringReact controlled value
type'text' | 'password' | 'email' | 'number' | 'tel' | 'url' | 'search''text'Input type
variant'outline' | 'filled' | 'ghost''outline'Visual variant
size'sm' | 'md' | 'lg''md'Height and font size
clearablebooleanfalseShow clear button when there is a value
errorbooleanfalseError border / ring
disabledbooleanfalseDisabled
readonlybooleanfalseRead-only
placeholderstringPlaceholder text

反馈与讨论

Input · Discussion

0
0 / 600
一键发送
正在加载评论...