フォーム
ラジオボタン
複数の選択肢から 1 つを選ぶ、小さな円形のコントロール。ネイティブのラジオボタンに適用します。
このページの内容
ラジオボタンは小さな円形のコントロールで、選択すると色が付き、中央に点が表示されます。丸いラジオボタンは一つだけ選べることを、四角いチェックボックスは複数選べることを示します。ネイティブの<input type="radio">に.radioを指定し、ラベルのテキストと一緒に<label class="check">で囲むと、行全体を操作できます。
ラジオボタン
<fieldset class="fieldset"> <legend class="fieldset-legend">Visibility</legend> <label class="check"> <input type="radio" class="radio" name="visibility" value="public" checked> Public </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="team"> Team only </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="private"> Private </label></fieldset><fieldset className="fieldset"> <legend className="fieldset-legend">Visibility</legend> <label className="check"> <input type="radio" className="radio" name="visibility" value="public" defaultChecked /> Public </label> <label className="check"> <input type="radio" className="radio" name="visibility" value="team" /> Team only </label> <label className="check"> <input type="radio" className="radio" name="visibility" value="private" /> Private </label></fieldset><fieldset class="fieldset"> <legend class="fieldset-legend">Visibility</legend> <label class="check"> <input type="radio" class="radio" name="visibility" value="public" checked> Public </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="team"> Team only </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="private"> Private </label></fieldset><template> <fieldset class="fieldset"> <legend class="fieldset-legend">Visibility</legend> <label class="check"> <input type="radio" class="radio" name="visibility" value="public" checked> Public </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="team"> Team only </label> <label class="check"> <input type="radio" class="radio" name="visibility" value="private"> Private </label> </fieldset></template>#グループ
同じnameを持つラジオボタンは一つのグループになります。一つを選ぶと他の選択が解除され、矢印キーでグループ内の選択を移動できます。グループをfieldsetで囲み、legendに選択肢が答える質問を記述します。
#横並び
短い選択肢が少数なら、横に並べられます。どのラベルがどのラジオボタンに対応するかがわかるよう、選択肢同士の間隔は、ボタンとラベルの間隔より広く取ります。
横並び
<fieldset class="fieldset"> <legend class="fieldset-legend">Billing period</legend> <div class="flex flex-wrap gap-lg"> <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label> <label class="check"><input type="radio" class="radio" name="period"> Yearly</label> </div></fieldset><fieldset className="fieldset"> <legend className="fieldset-legend">Billing period</legend> <div className="flex flex-wrap gap-lg"> <label className="check"> <input type="radio" className="radio" name="period" defaultChecked /> Monthly </label> <label className="check"><input type="radio" className="radio" name="period" /> Yearly</label> </div></fieldset><fieldset class="fieldset"> <legend class="fieldset-legend">Billing period</legend> <div class="flex flex-wrap gap-lg"> <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label> <label class="check"><input type="radio" class="radio" name="period"> Yearly</label> </div></fieldset><template> <fieldset class="fieldset"> <legend class="fieldset-legend">Billing period</legend> <div class="flex flex-wrap gap-lg"> <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label> <label class="check"><input type="radio" class="radio" name="period"> Yearly</label> </div> </fieldset></template>#無効状態
無効にしたラジオボタンは薄く表示され、ラベルには無効状態の文字色が適用されます。選択肢を個別に無効にすることも、fieldsetを無効にしてグループ全体を無効にすることもできます。
無効状態
<fieldset class="fieldset"> <legend class="fieldset-legend">Region</legend> <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label> <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label> <label class="check"> <input type="radio" class="radio" name="region" disabled> Virginia, at capacity </label></fieldset><fieldset className="fieldset"> <legend className="fieldset-legend">Region</legend> <label className="check"> <input type="radio" className="radio" name="region" defaultChecked /> Tokyo </label> <label className="check"><input type="radio" className="radio" name="region" /> Frankfurt</label> <label className="check"> <input type="radio" className="radio" name="region" disabled /> Virginia, at capacity </label></fieldset><fieldset class="fieldset"> <legend class="fieldset-legend">Region</legend> <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label> <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label> <label class="check"> <input type="radio" class="radio" name="region" disabled> Virginia, at capacity </label></fieldset><template> <fieldset class="fieldset"> <legend class="fieldset-legend">Region</legend> <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label> <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label> <label class="check"> <input type="radio" class="radio" name="region" disabled> Virginia, at capacity </label> </fieldset></template>#コントロールの選び方
ラジオボタンは、すべての選択肢を1行に一つずつ、まとめて表示します。単一選択には、用途に応じて以下のコントロールも使えます。
- セグメントコントロールは、ビューの切り替えなど、短い選択肢を2〜5個、1行に並べる場合に使います。
- セレクトは、選択肢が収まりきらない場合や、表示スペースが限られる場合に使います。
- チョイスは、選択肢ごとに見出しと説明文が必要な場合に使います。
- チップは、選択すると表示内容がすぐに切り替わるフィルターに使います。
#アクセシビリティ
- グループ内のすべてのラジオボタンに同じ
nameを指定してください。共有の指定がないと、選択は排他的にならず、矢印キーでも選択肢間を移動できません。 - グループにはタブ順上の停止位置が一つあります。Tabを押すと選択中のラジオボタンにフォーカスが移り、未選択の場合は先頭に移ります。そこから矢印キーで移動できます。
- 妥当な既定の選択肢がある場合は、あらかじめ選択しておきます。未選択の状態で始めると、利用者が一度選択した後に未選択へ戻すことはできません。
#クラス
| クラス | 説明 |
|---|---|
radio | ネイティブの type="radio" 入力。円形のくぼみ |