For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/v0.4.0/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/v0.4.0/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/v0.4.0/components/native-select.md.

原生选择器

原生选择器让用户从较短的固定选项中选择一个值,并保留操作系统熟悉的交互与无障碍能力。

实时预览

为当前订单选择一种水果。

用法

引入 CSS

导入 Tailwind 和一个完整的 A3S UI 样式包。

@import "tailwindcss";
@import "@a3s-lab/ui/a3s.css";

或者只导入基本CSS、原生选择CSS组件和一个样式包。

@import "tailwindcss";
@import "@a3s-lab/ui/base.css";
@import "@a3s-lab/ui/components/native-select.css";
@import "@a3s-lab/ui/styles/a3s.css";

使用CDN或批量程序导入?请参见安装页。

添加原生选择器 HTML

为原生 <select> 添加规范类 class="native-select",并继续使用标准 <option> 与 <optgroup> 元素。旧的 select 类仅作为迁移期视觉别名保留;新代码与框架适配器统一使用 native-select,避免与自定义 Select 根节点混淆。

<div class="field">
  <label for="native-select-fruit-html">水果</label>
  <select id="native-select-fruit-html" class="native-select" aria-describedby="native-select-fruit-help-html">
    <option value="">选择水果</option>
    <option value="apple">苹果</option>
    <option value="banana">香蕉</option>
    <option value="blueberry">蓝莓</option>
    <option value="pineapple">菠萝</option>
  </select>
  <p id="native-select-fruit-help-html">为当前订单选择一种水果。</p>
</div>

使用 Native Select 实现原生浏览器行为、表单集成和移动优化选择器。使用 Select 自定义选项内容、多选行为或 JavaScript API。

示例

组

实时预览

已禁用

实时预览

此选项由工作区策略统一管理。

无效

实时预览

required 让浏览器的有效性结果与手动声明的 aria-invalid 对同一个空值保持一致。

尺寸

实时预览

RTL

在选择元素或父元素上设置 dir="rtl"。

实时预览