フォーム
スイッチ
すぐに反映される設定向けの切り替えコントロールです。オンにすると、パール調のつまみがインク色のトラック上をスライドします。
このページの内容
スイッチは、くぼんだトラックの上をパール調のつまみが滑り、オンになるとトラックがインク色になるコントロールです。すぐに反映する設定には、ネイティブのチェックボックスに .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 のトラック。既定は 22pxswitch と併用します |
switch-lg | 26px のトラック。既定は 22pxswitch と併用します |