Preview Updated 2026-05-10

Search input

Input preset with a search icon, clear button, and optional shortcut hint. Pressing Enter fires the search event.

Basic usage

A fixed search icon on the left; when the value is non-empty an × clear button appears on the right and clicking it clears and fires clear. Enter fires search(value).

背景 视口
src/App.vue
<script setup lang="ts">
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const q = ref('');
function handleSearch(v: string) {
  console.log('search:', v);
}
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput v-model="q" placeholder="搜索文档…" @search="handleSearch" />
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const q = ref('');
function handleSearch(v) {
  console.log('search:', v);
}
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput v-model="q" placeholder="搜索文档…" @search="handleSearch" />
  </div>
</template>
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [q, setQ] = useState('');
  function handleSearch(v: string) {
    console.log('search:', v);
  }
  return (
    <>
      <div style={{ maxWidth: "24rem" }}>
          <CfSearchInput value={q} onChange={setQ} placeholder="搜索文档…" onSearch={handleSearch} />
        </div>
    </>
  );
}
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [q, setQ] = useState('');
  function handleSearch(v) {
    console.log('search:', v);
  }
  return (
    <>
      <div style={{ maxWidth: "24rem" }}>
          <CfSearchInput value={q} onChange={setQ} placeholder="搜索文档…" onSearch={handleSearch} />
        </div>
    </>
  );
}

Shortcut hint

shortcut mounts a kbd hint at the far right. Often paired with a page-level listener on Ctrl K / ⌘K to focus the search box.

背景 视口
src/App.vue
<script setup lang="ts">
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const q = ref('');
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput v-model="q" placeholder="按 Ctrl K 聚焦" shortcut="Ctrl K" />
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const q = ref('');
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput v-model="q" placeholder="按 Ctrl K 聚焦" shortcut="Ctrl K" />
  </div>
</template>
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [q, setQ] = useState('');
  const [q, setQ] = useState('');
  return (
    <>
      <CfSearchInput value={q} onChange={setQ} placeholder="Press Ctrl K to focus" shortcut="Ctrl K" />
    </>
  );
}
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [q, setQ] = useState('');
  const [q, setQ] = useState('');
  return (
    <>
      <CfSearchInput value={q} onChange={setQ} placeholder="Press Ctrl K to focus" shortcut="Ctrl K" />
    </>
  );
}

Three sizes

size matches Input / Select — sm / md (default) / lg.

背景 视口
src/App.vue
<script setup lang="ts">
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const a = ref('');
const b = ref('');
const c = ref('');
</script>
<template>
  <div class="demo-stack" style="max-width: 24rem;">
    <CfSearchInput v-model="a" size="sm" placeholder="size = sm" />
    <CfSearchInput v-model="b" size="md" placeholder="size = md" />
    <CfSearchInput v-model="c" size="lg" placeholder="size = lg" />
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { CfSearchInput } from '@chufix-design/vue';

const a = ref('');
const b = ref('');
const c = ref('');
</script>
<template>
  <div class="demo-stack" style="max-width: 24rem;">
    <CfSearchInput v-model="a" size="sm" placeholder="size = sm" />
    <CfSearchInput v-model="b" size="md" placeholder="size = md" />
    <CfSearchInput v-model="c" size="lg" placeholder="size = lg" />
  </div>
</template>
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [a, setA] = useState('');
  const [a, setA] = useState('');
  const [b, setB] = useState('');
  const [b, setB] = useState('');
  const [c, setC] = useState('');
  const [c, setC] = useState('');
  return (
    <>
      <CfSearchInput value={a} onChange={setA} size="sm" />
      <CfSearchInput value={b} onChange={setB} size="md" />
      <CfSearchInput value={c} onChange={setC} size="lg" />
    </>
  );
}
import { useState } from 'react';
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  const [a, setA] = useState('');
  const [a, setA] = useState('');
  const [b, setB] = useState('');
  const [b, setB] = useState('');
  const [c, setC] = useState('');
  const [c, setC] = useState('');
  return (
    <>
      <CfSearchInput value={a} onChange={setA} size="sm" />
      <CfSearchInput value={b} onChange={setB} size="md" />
      <CfSearchInput value={c} onChange={setC} size="lg" />
    </>
  );
}

Disabled

disabled greys the control and ignores clicks.

背景 视口
src/App.vue
<script setup lang="ts">
import { CfSearchInput } from '@chufix-design/vue';
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput model-value="(已禁用)" disabled />
  </div>
</template>
<script setup>
import { CfSearchInput } from '@chufix-design/vue';
</script>
<template>
  <div style="max-width: 24rem;">
    <CfSearchInput model-value="(已禁用)" disabled />
  </div>
</template>
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <CfSearchInput value="(disabled)" disabled />
    </>
  );
}
import { CfSearchInput } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <CfSearchInput value="(disabled)" disabled />
    </>
  );
}

API

PropTypeDefaultDescription
modelValue (Vue) / value (React)string''Current value
placeholderstring'Search…'Placeholder hint
size'sm' | 'md' | 'lg''md'Height
disabledbooleanfalseDisabled
clearablebooleantrueShow clear button (when value is non-empty)
shortcutstringRight-side kbd hint text

Events:

  • Vue: @update:modelValue, @search, @clear
  • React: onChange, onSearch, onClear

反馈与讨论

Search input · Discussion

0
0 / 600
正在加载评论...