For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/v0.2.0/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/v0.2.0/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/v0.2.0/components/switch.md.
  • 简体中文
  • v0.2.0
  • 开关

    Live previewHTML · CSS · JavaScript

    用途

    Include CSS

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

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

    或者仅导入基本 CSS、Switch 组件 CSS 和一个样式包。

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

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

    Add your switch HTML

    Add class="input" and role="switch" to a native checkbox. Use a native <label> or aria-label for accessible naming.

    <input type="checkbox" role="switch" class="input" />

    HTML 结构

    <input type="checkbox" role="switch" class="input">
    The switch control. Use native checkbox state: add checked for an initially enabled switch, disabled for a disabled switch, and aria-invalid="true" for invalid state.
    data-size="sm" Optional
    Renders the smaller switch size.

    示例

    说明

    Live previewHTML · CSS · JavaScript

    Focus is shared across devices, and turns off when you leave the app.

    选择卡

    Use a wrapping <label> when the whole card should toggle the switch.

    Live previewHTML · CSS · JavaScript

    已禁用

    当周围字段应使用禁用样式时,将 disabled 添加到开关,将 data-disabled="true" 添加到字段包装器。

    Live previewHTML · CSS · JavaScript

    无效

    aria-invalid="true" 添加到交换机,并将 data-invalid="true" 添加到字段包装器。

    Live previewHTML · CSS · JavaScript

    You must accept the terms and conditions to continue.

    尺寸

    使用data-size="sm"渲染较小的开关尺寸。

    Live previewHTML · CSS · JavaScript

    RTL

    切换字段布局使用文档方向。在字段或祖先上设置 dir="rtl"

    Live previewHTML · CSS · JavaScript

    يتم مشاركة التركيز عبر الأجهزة، ويتم إيقاف تشغيله عند مغادرة التطبيق.