スワイプ
行を横にスライドすると、その行で使える操作が表示されます。
このページの内容
スワイプは、行を横にずらして操作を表示するコンポーネントです。行はスクロール領域になっており、行と同じ幅のコンテンツを表示する位置と、行の末尾側に隠れた操作を表示する位置の 2 か所で止まります。ブラウザー標準のスクロールを使うため、指、トラックパッド、Tab キーのいずれでも操作を表示でき、スクリプトは不要です。
スワイプ
<div class="sheet sheet-raised overflow-hidden w-full max-w(360)"> <div class="swipe"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AL</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p> <p class="m(0) fg-text-muted">The notes on the engine are ready.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Ada Lovelace</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Ada Lovelace</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AT</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Alan Turing</p> <p class="m(0) fg-text-muted">Can machines think? A short reply.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Alan Turing</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Alan Turing</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">GH</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Grace Hopper</p> <p class="m(0) fg-text-muted">The compiler passes every test.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Grace Hopper</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Grace Hopper</span> </button> </div> </div></div><div className="sheet sheet-raised overflow-hidden w-full max-w(360)"> <div className="swipe"> <div className="swipe-content flex items-center gap-sm p(12)"> <span className="avatar">AL</span> <div className="min-w(0)"> <p className="m(0) fg-text-strong font-medium">Ada Lovelace</p> <p className="m(0) fg-text-muted">The notes on the engine are ready.</p> </div> </div> <div className="swipe-actions"> <button className="swipe-action" type="button"> Archive<span className="sr-only">Ada Lovelace</span> </button> <button className="swipe-action swipe-action-danger" type="button"> Delete<span className="sr-only">Ada Lovelace</span> </button> </div> </div> <div className="swipe bt(1) bt-solid b-line-hair"> <div className="swipe-content flex items-center gap-sm p(12)"> <span className="avatar">AT</span> <div className="min-w(0)"> <p className="m(0) fg-text-strong font-medium">Alan Turing</p> <p className="m(0) fg-text-muted">Can machines think? A short reply.</p> </div> </div> <div className="swipe-actions"> <button className="swipe-action" type="button"> Archive<span className="sr-only">Alan Turing</span> </button> <button className="swipe-action swipe-action-danger" type="button"> Delete<span className="sr-only">Alan Turing</span> </button> </div> </div> <div className="swipe bt(1) bt-solid b-line-hair"> <div className="swipe-content flex items-center gap-sm p(12)"> <span className="avatar">GH</span> <div className="min-w(0)"> <p className="m(0) fg-text-strong font-medium">Grace Hopper</p> <p className="m(0) fg-text-muted">The compiler passes every test.</p> </div> </div> <div className="swipe-actions"> <button className="swipe-action" type="button"> Archive<span className="sr-only">Grace Hopper</span> </button> <button className="swipe-action swipe-action-danger" type="button"> Delete<span className="sr-only">Grace Hopper</span> </button> </div> </div></div><div class="sheet sheet-raised overflow-hidden w-full max-w(360)"> <div class="swipe"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AL</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p> <p class="m(0) fg-text-muted">The notes on the engine are ready.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Ada Lovelace</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Ada Lovelace</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AT</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Alan Turing</p> <p class="m(0) fg-text-muted">Can machines think? A short reply.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Alan Turing</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Alan Turing</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">GH</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Grace Hopper</p> <p class="m(0) fg-text-muted">The compiler passes every test.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Grace Hopper</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Grace Hopper</span> </button> </div> </div></div><template> <div class="sheet sheet-raised overflow-hidden w-full max-w(360)"> <div class="swipe"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AL</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Ada Lovelace</p> <p class="m(0) fg-text-muted">The notes on the engine are ready.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Ada Lovelace</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Ada Lovelace</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">AT</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Alan Turing</p> <p class="m(0) fg-text-muted">Can machines think? A short reply.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Alan Turing</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Alan Turing</span> </button> </div> </div> <div class="swipe bt(1) bt-solid b-line-hair"> <div class="swipe-content flex items-center gap-sm p(12)"> <span class="avatar">GH</span> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Grace Hopper</p> <p class="m(0) fg-text-muted">The compiler passes every test.</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> Archive<span class="sr-only">Grace Hopper</span> </button> <button class="swipe-action swipe-action-danger" type="button"> Delete<span class="sr-only">Grace Hopper</span> </button> </div> </div> </div></template>#仕組み
swipe は、スクロールバーを表示せず、スナップを必須とする横スクロール領域です。swipe-content は行と同じ幅で、先頭側の端でスナップします。その後ろに続く swipe-actions は、末尾側の端でスナップします。途中でスクロールを止めると近い方の位置に収まり、元の位置まで戻すと行が閉じます。
コンテンツの背景は不透明です。シート やカードが公開する --surface-color から配置先の背景色を取得し、操作が現れるくぼみに浅い影を落とします。スクロール駆動アニメーションに対応するブラウザーでは、操作が現れるにつれてフェードインします。非対応のブラウザーでは、そのまま表示されます。
別の行を開いたときに元の行を閉じる処理や、操作を実行したときに行を削除する処理は、ページ側で実装します。スクリプトで行を閉じるには、その行の scrollLeft を 0 に設定します。
#操作
操作にはボタンまたはリンクを使い、ラベルだけを表示するか、ラベルの上に アイコン を配置します。各セルは幅 72px 以上で行全体の高さを占めるため、行の高さにかかわらずセル全体がタッチ領域になります。swipe-action-danger は取り消せない操作を示し、専用の淡い背景色と危険を示す前景色を使います。操作は 1 つか 2 つに絞り、破壊的な操作は最後に置きます。
アイコン付き
<div class="sheet sheet-raised overflow-hidden w-full max-w(360)"> <div class="swipe" id="swipe-open"> <div class="swipe-content flex items-center gap-sm p(16)"> <div class="min-w(0)"> <p class="m(0) fg-text-strong font-medium">Quarterly report.pdf</p> <p class="m(0) fg-text-muted">2.4 MB · Edited yesterday</p> </div> </div> <div class="swipe-actions"> <button class="swipe-action" type="button"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M10.625 11L10.6242 2.4693A0.625 0.625 0 0 0 9.3818 2.4083L9.375 2.5L9.377 11.05A0.6255 0.6255 0 0 0 9.4989 11.3735Q9.7145 11.5422 10 11.5422Q10.2855 11.5422 10.5011 11.3735A0.625 0.625 0 0 0 10.625 11Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M6.5 7.5L9.8586 10.8586A0.2 0.2 0 0 0 10.1414 10.8586L13.5 7.5" /><path d="M3 13.5L3 15.75A1.25 1.25 0 0 0 4.25 17L15.75 17A1.25 1.25 0 0 0 17 15.75L17 13.5" /> </svg> Save </button> <button class="swipe-action swipe-action-danger" type="button"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 5.5L17 5.5" /><path d="M5 5.5L5.4501 16.302A1.25 1.25 0 0 0 6.699 17.5L13.301 17.5A1.25 1.25 0 0 0 14.5499 16.302L15 5.5" /><path d="M7.5 5.5L7.5 3.5A1 1 0 0 1 8.5 2.5L11.5 2.5A1 1 0 0 1 12.5 3.5L12.5 5.5" /><path d="M8.5 9L8.5 14" /><path d="M11.5 9L11.5 14" /> </svg> Delete </button> </div> </div></div><script>document.getElementById('swipe-open').scrollLeft = 999</script>#アクセシビリティ
- スワイプはショートカットとして使い、必ず別の操作手段も用意します。 トラックパッドを使わずマウスだけで操作するユーザーは、行を横にスクロールできません。同じ操作を、行内または項目を開いた先の メニュー にも用意し、ポインターで操作できるようにします。
- 操作には、タブ順序に含まれるボタン要素を使います。ボタンにフォーカスが移ると、ブラウザーが自動でスクロールして表示するため、キーボード操作に追加の実装は不要です。フォーカスリングはセルの内側に描画されるため、スクロール領域の端で切れません。
- アイコンだけで表示する操作には、アクセシブルな名前が必要です。アイコンの下にラベルを添えると、文字を読んで操作を見つけやすくなります。
- 破壊的な操作は実行前に確認するか、トースト から取り消せるようにします。
#クラス
| クラス | 説明 |
|---|---|
swipe | スクロールバーのない横スクロール行。コンテンツまたはアクションの位置で止まります。 |
swipe-content | 通常時に行が表示する内容。行全体の幅を使い、行が載る面と同じ背景色で表示する |
swipe-actions | 末尾側の縁の奥にあるくぼみに配置したアクション |
swipe-action | ボタンまたはリンクに1つのアクション。行と同じ高さで幅72px以上のセルに、語句のみ、または語句の上にアイコンを配置 |
swipe-action-danger | 取り消せないアクションです。専用の淡い背景に、危険を示す前景色で表示します。swipe-action と併用します |