Skip to content
fandhe-frontendcore v0.4.3
GitHub

Button Group

関連ボタンを角丸・境界線で連結してひとつのグループに見せる shadcn/ui Button Group 相当の部品です(参照軸はイシュー #2001、shadcn/ui 追加はイシュー #2004)。fandhe-frontend-headless-ui の button_group mod が構造・アクセシビリティ(WAI-ARIA)・表示状態(data-*)のみを提供する unstyled 部品で、root(role="group")/ separator / text の 3 anatomy パーツを持ちます。

toolbar mod の roving tabindex(矢印キーでフォーカスが移動する複合ウィジェット)とは異なり、button_group は 静的なグループ化です。子ボタンのフォーカス順序はネイティブの Tab 順序に委ね、状態機械を持ちません。ネスト(グループの中に別のグループ)も許容します。

アクセシビリティ

  • root は role="group" を固定付与します。WAI-ARIA は group ロールへの aria-orientation を許可していないため、aria-orientation は付与しません。向きは data-orientation("horizontal" / "vertical")のみで表現します。
  • label を渡すと aria-label を出力します(空文字列のときは省略します)。
  • separator は role="separator" を固定付与し、グループ自身の向きと直交する aria-orientation/data-orientation を出力します(横並びグループの区切り線は縦線になるため vertical)。
  • キーボード操作はネイティブ button 要素の Tab/Shift+Tab によるフォーカス移動のみに依存します。独自キーハンドラは持ちません。
  • 先頭/末尾ボタンの角丸連結は本 mod の責務外です。CSS の :first-child/:last-child セレクタで表現します(装飾を headless-ui へ持ち込まない責務境界の判断)。

自前 CSS の最小例:

CSS
[data-scope="button-group"][data-part="root"] {
  display: inline-flex;
}
[data-scope="button-group"][data-part="root"][data-orientation="vertical"] {
  flex-direction: column;
}
[data-scope="button-group"][data-part="root"] > button:first-child {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
[data-scope="button-group"][data-part="root"] > button:last-child {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}

fandhe-frontend-pre-styled-ui に対応するスタイル済み部品があります。Themes 版は Button Group を参照してください。

関連 API: fandhe-frontend-headless-ui API

Demo

枠線・余白は docs サイト側のデモ枠であり、fandhe-frontend-headless-ui 自体はスタイルを持ちません。

Sort by:

Features

  • 関連ボタンを角丸・境界線で連結してひとつのグループに見せる shadcn/ui Button Group 相当(参照軸 #2001)。root(div)/ separator(div)/ text(div)の 3 anatomy パーツを持つ(button_group.rs モジュール doc)。
  • role="group" の静的なグループ化であり、mod@toolbar の roving tabindex 状態機械とは異なりネイティブ Tab 順序に委ねる(mod@fieldset と同じく状態機械を持たない)。
  • role="group" へ aria-orientation は付与しない(WAI-ARIA 上 group ロールへの aria-orientation は非許可、toolbar::toggle_group と同じ判断)。向きは data-orientation のみで表現する。
  • 先頭/末尾ボタンの角丸連結は本モジュールの責務外(.claude/rules/coding-rust.md §3.25、装飾は pre-styled-ui 側)。CSS の :first-child/:last-child セレクタで表現する。
  • separator はグループ自身の向きと直交する aria-orientation/data-orientation を出力する(横並びグループの区切り線は縦線になるため vertical、toolbar::separator/action_bar::separator と同じ判断)。
  • ネスト(グループの中にグループ)を許容する。内側の root は自身の data-orientation のみを持ち、外側の値へは影響しない。

Anatomy

root
  text
  separator

API Reference

Arguments

NameTypeDefaultDescription
root(orientation, label, attrs, children)Orientation, &str—label が非空のとき aria-label へ出力する(空文字列のときは省略)。aria-orientation は出力しない。
separator(group_orientation, attrs, children)Orientation—グループ自身の向きと直交する aria-orientation/data-orientation を出力する。
text(attrs, children)Vec<(&str, &str)>, Vec<Node>—shadcn/ui の ButtonGroupText 相当のラベル用非ボタン要素(div)。固定付与属性を持たない。

Data Attributes

PartAttributeObserved Values
rootdata-orientationhorizontal, vertical
separatordata-orientationvertical

Examples

Vertical 単体構成

root を Vertical 向きで単体使用する最小構成です。

ネスト(グループの中にグループ)

外側 Vertical・内側 Horizontal のグループを組み合わせた構成です。

自前 CSS の最小例

data-scope / data-part / data-orientation 属性セレクタで先頭/末尾ボタンの角丸連結・区切り線を組み立てる最小例です。headless-ui 自体はスタイルを持ちません。

CSS
[data-scope="button-group"][data-part="root"] {
  display: inline-flex;
}
[data-scope="button-group"][data-part="root"][data-orientation="vertical"] {
  flex-direction: column;
}
[data-scope="button-group"][data-part="root"] > button:not(:first-child) {
  margin-inline-start: -1px;
}
[data-scope="button-group"][data-part="root"] > button:first-child {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
[data-scope="button-group"][data-part="root"] > button:last-child {
  border-start-start-radius: 0;
  border-end-start-radius: 0;
}
[data-scope="button-group"][data-part="separator"] {
  width: 1px;
  background: #d1d5db;
}

Accessibility

Keyboard Interactions

KeyDescription
Tab / Shift+Tabネイティブ button 要素由来のフォーカス移動のみ。roving tabindex・矢印キーの状態機械は持たない(静的なグループ化のため、button_group.rs モジュール doc「role="group" の静的グループ」節)。

WAI-ARIA

AttributeDescription
role="group"root に固定付与。aria-orientation は付与しない(WAI-ARIA 上 group ロールへの aria-orientation は非許可)。
data-orientationroot/separator に固定付与。root は呼び出し側指定の向き、separator はそれと直交する向き。
role="separator" / aria-orientationseparator に固定付与。グループ自身の向きと直交する値を出力する(toolbar::separator と同じ判断)。