表單
開關
珍珠色滑塊會滑到以介面前景色呈現的軌道上,適用於立即生效的設定。
本頁內容
開關採用凹槽式軌道,開啟時,珍珠色滑塊會滑到墨色軌道上。對於立即生效的設定,請在原生核取方塊上套用 .switch 並設定 role="switch"。若選項要隨表單一起送出,使用核取方塊會更清楚。
開關
<label class="check"> <input type="checkbox" role="switch" class="switch" checked> Email notifications</label><label className="check"> <input type="checkbox" role="switch" className="switch" defaultChecked /> Email notifications</label><label class="check"> <input type="checkbox" role="switch" class="switch" checked> Email notifications</label><template> <label class="check"> <input type="checkbox" role="switch" class="switch" checked> Email notifications </label></template>#尺寸
尺寸
<input type="checkbox" role="switch" class="switch switch-sm" aria-label="Small" checked><input type="checkbox" role="switch" class="switch" aria-label="Medium" checked><input type="checkbox" role="switch" class="switch switch-lg" aria-label="Large" checked><> <input type="checkbox" role="switch" className="switch switch-sm" aria-label="Small" defaultChecked /> <input type="checkbox" role="switch" className="switch" aria-label="Medium" defaultChecked /> <input type="checkbox" role="switch" className="switch switch-lg" aria-label="Large" defaultChecked /></><input type="checkbox" role="switch" class="switch switch-sm" aria-label="Small" checked><input type="checkbox" role="switch" class="switch" aria-label="Medium" checked><input type="checkbox" role="switch" class="switch switch-lg" aria-label="Large" checked><template> <input type="checkbox" role="switch" class="switch switch-sm" aria-label="Small" checked> <input type="checkbox" role="switch" class="switch" aria-label="Medium" checked> <input type="checkbox" role="switch" class="switch switch-lg" aria-label="Large" checked></template>#在設定清單中使用
設定清單
<div class="sheet flex flex-col p(0)"> <label class="check justify-between gap-lg px-lg py-md"> <span>Automatic updates</span> <input type="checkbox" role="switch" class="switch" checked> </label> <label class="check justify-between gap-lg px-lg py-md bt(1) bt-solid bt-line-hair"> <span>Usage analytics</span> <input type="checkbox" role="switch" class="switch"> </label></div><div className="sheet flex flex-col p(0)"> <label className="check justify-between gap-lg px-lg py-md"> <span>Automatic updates</span> <input type="checkbox" role="switch" className="switch" defaultChecked /> </label> <label className="check justify-between gap-lg px-lg py-md bt(1) bt-solid bt-line-hair"> <span>Usage analytics</span> <input type="checkbox" role="switch" className="switch" /> </label></div><div class="sheet flex flex-col p(0)"> <label class="check justify-between gap-lg px-lg py-md"> <span>Automatic updates</span> <input type="checkbox" role="switch" class="switch" checked> </label> <label class="check justify-between gap-lg px-lg py-md bt(1) bt-solid bt-line-hair"> <span>Usage analytics</span> <input type="checkbox" role="switch" class="switch"> </label></div><template> <div class="sheet flex flex-col p(0)"> <label class="check justify-between gap-lg px-lg py-md"> <span>Automatic updates</span> <input type="checkbox" role="switch" class="switch" checked> </label> <label class="check justify-between gap-lg px-lg py-md bt(1) bt-solid bt-line-hair"> <span>Usage analytics</span> <input type="checkbox" role="switch" class="switch"> </label> </div></template>#停用
停用
<input type="checkbox" role="switch" class="switch" aria-label="Beta features" disabled><input type="checkbox" role="switch" class="switch" aria-label="Security alerts" checked disabled><> <input type="checkbox" role="switch" className="switch" aria-label="Beta features" disabled /> <input type="checkbox" role="switch" className="switch" aria-label="Security alerts" defaultChecked disabled /></><input type="checkbox" role="switch" class="switch" aria-label="Beta features" disabled><input type="checkbox" role="switch" class="switch" aria-label="Security alerts" checked disabled><template> <input type="checkbox" role="switch" class="switch" aria-label="Beta features" disabled> <input type="checkbox" role="switch" class="switch" aria-label="Security alerts" checked disabled></template>#無障礙
- 保留
role="switch",讓輔助科技報讀「開啟」或「關閉」,取代核取方塊的勾選狀態。 - 每個開關都需要標籤。可用
<label>包住開關,或使用<label for>或aria-label。 - 輸入控制項保留原生行為,可取得焦點並用空白鍵切換。
#類別
| 類別 | 說明 |
|---|---|
switch | 帶有 role="switch" 的原生核取方塊。滑軌高 22px,滑塊與滑軌邊緣相距 3px。觸控螢幕上仍使用同一尺寸的滑軌,觸控區擴至 44px。文字從右向左排列時,滑塊的移動方向也會反轉 |
switch-sm | 滑軌高 18px,預設為 22px搭配 switch 使用 |
switch-lg | 滑軌高 26px,預設為 22px搭配 switch 使用 |