Skip to content
fandhe-frontend
GitHub

Toggle Group

複数の押下可能なボタンをグループ化する unstyled 部品です。「高々 1 項目が押下される」状態機械(常時 deselectable)を提供し、各項目は独立した Toggle の集合として振る舞います。

Themes 版(fandhe-frontend-pre-styled-ui)はこの構造へ既定 CSS を追加するだけの薄いラッパーであり、CSS は持ちません。スタイル済みの表示例は Toggle Group を参照してください。

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

Demo

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

Features

  • Root(`<div role="group">`)/Item(`<button type="button">`)の 2 anatomy パーツと、「高々 1 項目が押下される」状態機械 `ToggleGroup`(single モード、常時 deselectable)を提供する。
  • 各 `item` は単体の `crate::toggle::root` と同じ `aria-pressed`/`data-state`(on/off)語彙を持つ(ToggleGroup の各項目は独立した Toggle の集合という ark-ui の位置付け)。
  • `orientation` が `Some` のときのみ `data-orientation` を付与する。`role="group"` は WAI-ARIA 上 `aria-orientation` を許可されていないため `aria-orientation` は付与しない。
  • `labelled_by` が `Some` のときのみ `aria-labelledby` を付与する(名前なしの関連付けを作らない方針)。
  • roving focus(矢印キーによるフォーカス移動)はクライアントランタイム側の責務であり、本コンポーネントのスコープ外。

Anatomy

root
  item

API Reference

Arguments

NameTypeDefaultDescription
disabledboolfalseroot 全体の無効化状態。
orientationOption<Orientation>None`Some` のときのみ `data-orientation` を付与する。
labelled_byOption<&str>None`Some` のときのみ `aria-labelledby` を付与する。
pressed / disabled (item)boolfalse各 `item` の押下・無効化状態。`data-state`(on/off)・`aria-pressed`・`data-pressed` へ反映する。
value (item)&str(必須)`data-value` としてそのまま出力する項目値(既定エスケープ経由)。

Data Attributes

PartAttributeObserved Values
itemdata-pressed
itemdata-stateoff, on
itemdata-valuebold, italic

Examples

縦方向 + ラベル関連付け

`orientation` に `Some(Orientation::Vertical)`、`labelled_by` に `Some("...")` を渡すと `data-orientation="vertical"` と `aria-labelledby` が付与されます。

Accessibility

Keyboard Interactions

KeyDescription
Tab / Space / Enter各 `item` はネイティブ `<button type="button">` であり、フォーカス・押下操作はブラウザ既定動作で成立する。

WAI-ARIA

AttributeDescription
role`root` へ `"group"` を固定付与する。
aria-pressed各 `item` へ現在の押下状態を付与する。