ロービングタブインデックス
stimeo--roving
並んだ項目を Tab の 1 停止にまとめ、その中は矢印キーで移動します。
ボタンやタブが並んだまとまりを、Tab では 1 回しか止まらないようにします。中を移動するのは矢印キーです。項目が 20 個あっても、キーボードで通り抜けるときに 20 回止まりません。横並びなら左右、縦並びなら上下、両方向にも対応します。Home と End で両端へ飛べます。端まで来たら反対側へ回るか、そこで止まるかを選べます。クリックやプログラムからフォーカスが入ったときも、Tab の止まる位置が追いつきます。項目があとから増えても、個別の設定は要りません。
グループへ Tab で入り、矢印キーでボタンの間を移動します。Home と End で両端へ飛べます。
キーボード操作
| キー | 動作 |
|---|---|
| → / ← | 次/前の項目へ(横向き / 両方向のとき)。RTL では左右が入れ替わる。 |
| ↓ / ↑ | 次/前の項目へ(縦向き / 両方向のとき)。 |
| Home / End | 先頭/末尾の到達可能な項目へ(Home/End 有効時)。 |
| Ctrl+Home / Ctrl+End など | 修飾キー付きの Home/End は消費せず、ブラウザに渡す。 |
<%# Roving tabindex demo: the toolbar is a single Tab stop. Tab in once, then the
arrow keys move focus (and the tab stop) between buttons; Home/End jump to the ends
and movement wraps (the defaults). role="toolbar" + the accessible name are the
consumer's — the library owns only tabindex + focus movement, so this is "build your
own toolbar with the roving primitive". The buttons are plain actions; demo.css owns
the look. %>
<div class="roving-demo">
<p class="roving-demo__hint"><%= t("components.roving.demo.hint") %></p>
<div class="roving-demo__group" role="toolbar"
aria-label="<%= t('components.roving.demo.group_label') %>"
data-controller="stimeo--roving"
data-stimeo--roving-orientation-value="both">
<button type="button" class="demo-trigger" data-stimeo--roving-target="item">
<%= t("components.roving.demo.items.previous") %>
</button>
<button type="button" class="demo-trigger" data-stimeo--roving-target="item">
<%= t("components.roving.demo.items.play") %>
</button>
<button type="button" class="demo-trigger" data-stimeo--roving-target="item">
<%= t("components.roving.demo.items.next") %>
</button>
<button type="button" class="demo-trigger" data-stimeo--roving-target="item">
<%= t("components.roving.demo.items.shuffle") %>
</button>
<button type="button" class="demo-trigger" data-stimeo--roving-target="item">
<%= t("components.roving.demo.items.repeat") %>
</button>
</div>
</div>
/*
* Presentation-only styles for the roving-tabindex demo. The library owns the single
* Tab stop (it sets tabindex) and focus movement; this CSS only lays out the toolbar
* row. The focused button is highlighted by the shared .demo-trigger :focus-visible
* outline, so the roving focus is visible without any extra rule here.
*/
.roving-demo {
display: flex;
flex-direction: column;
gap: 0.75rem;
align-items: flex-start;
}
.roving-demo__hint {
margin: 0;
color: var(--muted);
}
.roving-demo__group {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}
このデモに固有の消費側 JS はありません(挙動はコントローラが担います)。
これらのスタイルは共通のデザイントークン(ライト/ダーク両対応)を使います。共通スタイルも一緒にコピーし、ルート要素の data-theme を切り替えればダークになります。
このコンポーネントを動かすために HTML へ記述する data-* 属性です。ルート要素に下の data-controller を付け、その内側に各 target / value / action を配置します。
ルート要素に付与
data-controller="stimeo--roving"
ターゲット
| 名前 | 説明 | 属性 |
|---|---|---|
item
必須
|
巡回対象の item。矢印キーのロービングで一つの Tab 停止を形成する。 | data-stimeo--roving-target="item" |
値(Values)
| 名前 | 説明 | 属性 |
|---|---|---|
orientation
|
矢印キーの軸。horizontal / vertical / both。既定値は horizontal。 |
data-stimeo--roving-orientation-value |
wrap
|
矢印移動が端を越えて巡回するか(false なら端で停止)。既定値は true。 | data-stimeo--roving-wrap-value |
homeEnd
|
Home/End で先頭・末尾へ移動するか。既定値は true。 | data-stimeo--roving-home-end-value |
イベント
| 名前 | 説明 | イベント |
|---|---|---|
change
|
利用者操作で tabbable な item が変化したとき { index, item } で発火。確立・再調停は無音。 | stimeo--roving:change |
状態フック
ライブラリが操作するのはこれらの ARIA / data 属性、カスタムプロパティだけです。見た目は利用側 CSS がこれらに反応して作ります([aria-selected] / [aria-expanded] / var(--stimeo--…) などのセレクタでフックします)。
| フック | 対象 | 意味 |
|---|---|---|
tabindex |
item | tabbable な 1 つが 0、他は -1(単一の Tab 停止)。 |