选择器

触发器与 input 同视觉;弹层支持 ↑↓ 移动、Enter 选中、Esc / 外点关闭,选中值同步隐藏 input。

<div class="demo-col">  <div class="select" data-select>    <button class="select-trigger pressable focus-ring" type="button" aria-haspopup="listbox" aria-expanded="false">      <span class="select-value is-empty">选择一种水果</span>      <svg class="select-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>    </button>    <div class="select-panel" hidden>      <button class="select-option" type="button" data-value="apple">苹果</button>      <button class="select-option" type="button" data-value="banana">香蕉</button>      <button class="select-option" type="button" data-value="orange">橙子</button>    </div>    <input type="hidden" data-select-value name="fruit" />  </div></div>

安装

bun add @icen.ai/ui

一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):

import { initSelect } from '@icen.ai/ui/kit/select';initSelect();

也可以用脚手架直接打印引入行:

bunx --bun @icen.ai/ui add select

Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/select.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。

用法

import { initSelect } from '@icen.ai/ui/behaviors/select';initSelect();