コンテンツへスキップ

コンポーネント

スイッチ

設定を切り替え、変更をすぐに適用します。

使い方

基本

HTML
<bs:bsui-switch label="Email notifications" defaultChecked="true" />

設定項目

スイッチはすぐに反映されるため、一覧に保存ボタンは必要ありません。

HTML
<bs:bsui-stack direction="column" gap="4">
  <bs:bsui-switch name="deploys" label="Deploy summaries" defaultChecked="true" />
  <bs:bsui-switch name="failures" label="Build failures" defaultChecked="true" />
  <bs:bsui-switch name="news" label="Product news" />
</bs:bsui-stack>

読み取り専用と無効

読み取り専用のスイッチは値を表示したまま切り替えを拒み、無効なスイッチはさらに薄く表示されます。

HTML
<bs:bsui-stack direction="column" gap="4">
  <bs:bsui-switch label="Two factor authentication" defaultChecked="true" readOnly="true" />
  <bs:bsui-switch label="Single sign-on" disabled="true" />
</bs:bsui-stack>

カスタム値

オンとオフの状態には、onや空欄に限らず任意の値を送信できます。

Submits weekly while it is on and never while it is off.
HTML
<bs:bsui-field>
  <bs:bsui-field-label text="Digest emails" />
  <bs:bsui-switch name="digest" label="Send a weekly digest" checkedValue="weekly" uncheckedValue="never" defaultChecked="true" />
  <bs:bsui-field-description text="Submits weekly while it is on and never while it is off." />
</bs:bsui-field>

構造

スイッチは以下のブロックで構成されます。それぞれ独立したブロックで、親の内部でのみレンダリングされます。

  • bsui/switch
  • bsui/switch-thumb

属性

属性タイプデフォルト
defaultChecked toggle false
disabled toggle false
readOnly toggle false
required toggle false
name text —
checkedValue text on
uncheckedValue text —
label richtext —
bindText text —
nameAlt text —
onChange text —
checked text —

bsui/switch-thumb

このブロックは属性を受け取りません。