並べ替えリスト
ハンドルのドラッグまたはキー操作で項目の順序を変えられるリスト。
このページの内容
並べ替えリストは、ハンドルのドラッグまたはキー操作で項目の順序を変えられるリストです。並べ替えリスト自体は項目の行を生成しません。リスト、カードを積み重ねた列など、項目を収める任意の要素に適用し、各項目にハンドルを付けます。ハンドルは、移動する対象を名前に含めたボタンです。sortable のビヘイビアは、ほかの項目が場所を空けるなかで項目を運び、ドロップしたときに一度だけそのノードを移動します。
並べ替えリスト
<div class="max-w(420) mx-auto"> <ol class="list sortable" aria-label="Priorities this quarter"> <li class="list-row sortable-item" data-value="onboarding"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Onboarding"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="list-body"> <span class="list-title">Onboarding</span><span class="list-description">First run, invitations and the empty states</span> </span> <span class="list-end">Mar 2</span> </li> <li class="list-row sortable-item" data-value="billing"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Billing"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="list-body"> <span class="list-title">Billing</span><span class="list-description">Invoices in every currency</span> </span> <span class="list-end">Mar 16</span> </li> <li class="list-row sortable-item" data-value="search"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="list-body"> <span class="list-title">Search</span><span class="list-description">Filters that can be saved and shared</span> </span> <span class="list-end">Apr 6</span> </li> <li class="list-row sortable-item" data-value="exports"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Exports"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="list-body"> <span class="list-title">Exports</span><span class="list-description">CSV and PDF for every report</span> </span> <span class="list-end">Apr 27</span> </li> </ol> <p class="sortable-status" role="status"></p></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import GripVerticalIcon from '@master/icons-react/native/16/soft/grip-vertical'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="max-w(420) mx-auto"> <ol className="list sortable" aria-label="Priorities this quarter"> <li className="list-row sortable-item" data-value="onboarding"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Onboarding"> <GripVerticalIcon className="icon" /> </button> <span className="list-body"> <span className="list-title">Onboarding</span><span className="list-description">First run, invitations and the empty states</span> </span> <span className="list-end">Mar 2</span> </li> <li className="list-row sortable-item" data-value="billing"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Billing"> <GripVerticalIcon className="icon" /> </button> <span className="list-body"> <span className="list-title">Billing</span><span className="list-description">Invoices in every currency</span> </span> <span className="list-end">Mar 16</span> </li> <li className="list-row sortable-item" data-value="search"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Search"> <GripVerticalIcon className="icon" /> </button> <span className="list-body"> <span className="list-title">Search</span><span className="list-description">Filters that can be saved and shared</span> </span> <span className="list-end">Apr 6</span> </li> <li className="list-row sortable-item" data-value="exports"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Exports"> <GripVerticalIcon className="icon" /> </button> <span className="list-body"> <span className="list-title">Exports</span><span className="list-description">CSV and PDF for every report</span> </span> <span className="list-end">Apr 27</span> </li> </ol> <p className="sortable-status" role="status"></p> </div> )}<script> import { attach } from '@master/ui/behaviors' import GripVerticalIcon from '@master/icons-svelte/native/16/soft/grip-vertical'</script><div class="max-w(420) mx-auto" {@attach attach}> <ol class="list sortable" aria-label="Priorities this quarter"> <li class="list-row sortable-item" data-value="onboarding"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Onboarding"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Onboarding</span><span class="list-description">First run, invitations and the empty states</span> </span> <span class="list-end">Mar 2</span> </li> <li class="list-row sortable-item" data-value="billing"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Billing"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Billing</span><span class="list-description">Invoices in every currency</span> </span> <span class="list-end">Mar 16</span> </li> <li class="list-row sortable-item" data-value="search"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Search"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Search</span><span class="list-description">Filters that can be saved and shared</span> </span> <span class="list-end">Apr 6</span> </li> <li class="list-row sortable-item" data-value="exports"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Exports"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Exports</span><span class="list-description">CSV and PDF for every report</span> </span> <span class="list-end">Apr 27</span> </li> </ol> <p class="sortable-status" role="status"></p></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import GripVerticalIcon from '@master/icons-vue/native/16/soft/grip-vertical'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="max-w(420) mx-auto"> <ol class="list sortable" aria-label="Priorities this quarter"> <li class="list-row sortable-item" data-value="onboarding"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Onboarding"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Onboarding</span><span class="list-description">First run, invitations and the empty states</span> </span> <span class="list-end">Mar 2</span> </li> <li class="list-row sortable-item" data-value="billing"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Billing"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Billing</span><span class="list-description">Invoices in every currency</span> </span> <span class="list-end">Mar 16</span> </li> <li class="list-row sortable-item" data-value="search"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Search"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Search</span><span class="list-description">Filters that can be saved and shared</span> </span> <span class="list-end">Apr 6</span> </li> <li class="list-row sortable-item" data-value="exports"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Exports"> <GripVerticalIcon class="icon" /> </button> <span class="list-body"> <span class="list-title">Exports</span><span class="list-description">CSV and PDF for every report</span> </span> <span class="list-end">Apr 27</span> </li> </ol> <p class="sortable-status" role="status"></p> </div></template>#スタイルシートの描画内容
- ハンドル グリップアイコンを入れたボタンです。ポインターやキー操作が届くまでは控えめに表示され、カーソルは握った手の形になります。ハンドルの大きさは 24×28px です。タッチ画面では、グリップの位置を変えずに操作領域が 44px まで広がります。
touch-action: noneが指定されているため、ハンドルから始めたドラッグでページがスクロールすることはありません。項目のほかの部分では、通常どおりスクロールできます。 - 運ばれている項目 項目が持ち上がります。浮き上がったシートが項目の端から少しはみ出す大きさで周囲に広がるため、中身は動きません。浮き上がりを示す影が付き、1.5% だけ膨らみます。項目は、ビヘイビアが書き込む
--sortable-offsetによってポインターに追従し、ポインターと項目の間にイージングはかかりません。リストの細い罫線のように行の下に描かれる線は、項目が離れた元の行に残ります。 - 場所を空ける動き 運ばれている項目の元の位置と移動先の間にある項目が、
--sortable-sizeの分だけ滑るように位置をずらします。先頭方向へはsortable-item-back、末尾方向へはsortable-item-forwardです。--sortable-sizeは、持ち上げた時点で計測した、運ばれている項目の大きさとその後ろの間隔を合わせた値です。空いた隙間が移動先になります。元の位置は空いたままなので、どこから運んできたかがわかります。 - ドロップ 場所を空けた項目はすでに移動先に並んでいるため、空けた場所の解消と隙間へのノードの配置が 1 回の変更で行われます。各項目を
view-transition-name: match-elementによって個別の画像として扱うビュートランジションの中で、運ばれていた項目だけが、離した位置から移動先へ移動します。その間、ルート要素はaria-busy="true"を示し、ほかの項目は動きません。
ビュートランジションに対応していないブラウザーでは、運ばれていた項目はすぐに移動先に収まります。ほかの項目はすでに移動先にあります。動きを抑える設定では、膨らみ、滑るような移動、トランジションのいずれも行いません。
#カード
項目を収める要素であれば、何でも並べ替えられます。この例では、各項目が間隔をあけて積み重ねたカードです。カードが空ける場所には、この間隔も含まれます。運ばれているカードが乗るシートは、--sortable-radius によってカードと同じ角丸になります。
カード
<div class="max-w(360) mx-auto"> <ol class="list sortable gap-xs" aria-label="Release checklist" style="--sortable-radius: var(--radius-surface)"> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="freeze"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Freeze the branch"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="text-sm fg-text-strong">Freeze the branch</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="notes"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Write the release notes"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="text-sm fg-text-strong">Write the release notes</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="staging"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Deploy to staging"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="text-sm fg-text-strong">Deploy to staging</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="announce"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Announce the release"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="6" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="4" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="8" r="1" fill="currentColor" stroke="none" /><circle cx="6" cy="12" r="1" fill="currentColor" stroke="none" /><circle cx="10" cy="12" r="1" fill="currentColor" stroke="none" /> </svg> </button> <span class="text-sm fg-text-strong">Announce the release</span> </li> </ol> <p class="sortable-status" role="status"></p></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import GripVerticalIcon from '@master/icons-react/native/16/soft/grip-vertical'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="max-w(360) mx-auto"> <ol className="list sortable gap-xs" aria-label="Release checklist" style={{ '--sortable-radius': 'var(--radius-surface)' } as React.CSSProperties}> <li className="card sortable-item flex items-center gap-sm p-sm" data-value="freeze"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Freeze the branch"> <GripVerticalIcon className="icon" /> </button> <span className="text-sm fg-text-strong">Freeze the branch</span> </li> <li className="card sortable-item flex items-center gap-sm p-sm" data-value="notes"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Write the release notes"> <GripVerticalIcon className="icon" /> </button> <span className="text-sm fg-text-strong">Write the release notes</span> </li> <li className="card sortable-item flex items-center gap-sm p-sm" data-value="staging"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Deploy to staging"> <GripVerticalIcon className="icon" /> </button> <span className="text-sm fg-text-strong">Deploy to staging</span> </li> <li className="card sortable-item flex items-center gap-sm p-sm" data-value="announce"> <button type="button" className="sortable-handle" aria-pressed="false" aria-label="Move Announce the release"> <GripVerticalIcon className="icon" /> </button> <span className="text-sm fg-text-strong">Announce the release</span> </li> </ol> <p className="sortable-status" role="status"></p> </div> )}<script> import { attach } from '@master/ui/behaviors' import GripVerticalIcon from '@master/icons-svelte/native/16/soft/grip-vertical'</script><div class="max-w(360) mx-auto" {@attach attach}> <ol class="list sortable gap-xs" aria-label="Release checklist" style="--sortable-radius: var(--radius-surface)"> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="freeze"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Freeze the branch"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Freeze the branch</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="notes"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Write the release notes"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Write the release notes</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="staging"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Deploy to staging"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Deploy to staging</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="announce"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Announce the release"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Announce the release</span> </li> </ol> <p class="sortable-status" role="status"></p></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import GripVerticalIcon from '@master/icons-vue/native/16/soft/grip-vertical'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="max-w(360) mx-auto"> <ol class="list sortable gap-xs" aria-label="Release checklist" style="--sortable-radius: var(--radius-surface)"> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="freeze"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Freeze the branch"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Freeze the branch</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="notes"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Write the release notes"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Write the release notes</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="staging"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Deploy to staging"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Deploy to staging</span> </li> <li class="card sortable-item flex items-center gap-sm p-sm" data-value="announce"> <button type="button" class="sortable-handle" aria-pressed="false" aria-label="Move Announce the release"> <GripVerticalIcon class="icon" /> </button> <span class="text-sm fg-text-strong">Announce the release</span> </li> </ol> <p class="sortable-status" role="status"></p> </div></template>#ビヘイビア
sortable は、sortable クラスを持つルート要素を受け取り、ビヘイビアを解除する関数を返します。
import { sortable } from '@master/ui/behaviors/sortable.js'const priorities = sortable(document.querySelector('.sortable'))priorities.value // ['onboarding', 'billing', 'search', 'exports']- ポインター ハンドルを押したまま 4px を超えて動かすと、項目が持ち上がります。それ未満なら通常の押下として扱います。運んでいる間、ハンドルは
aria-pressed="true"を示し、項目はポインターに追従し、通過した項目が場所を空けます。移動先は、場所を空ける途中の位置ではなく、レイアウト上の項目の位置から判定するため、移動先が自身を追いかけるように揺れ動くことはありません。ポインターを離すと項目が移動し、Escape を押すと、ほかの項目が元の位置へ滑って戻るなかで項目も元の位置に戻ります。スクロールするリストでは、ポインターがリストのどちらかの端に近づくとリストがスクロールし、端に寄るほど速くなります。項目を動かせるのは、ドラッグを始めたポインターだけです。 - ドラッグしない操作 ハンドルを動かさずに押す、つまりクリックやタップをすると、Enter と同じように項目が持ち上がり、そのハンドルにフォーカスが移ります。続けてほかの項目のハンドルを押すと、その位置へ移動してドロップします。自分のハンドルをもう一度押すと、その場でドロップします。ドラッグできないポインターや、スクリーンリーダーのダブルタップでも、この方法でリストを並べ替えられます。
- キー操作 ハンドルで Enter または Space を押すと、項目が持ち上がります。リストの並びに沿った矢印キーで、項目を 1 つずつ移動します。矢印キーは項目を持ち上げるまで何もしないため、スクリーンリーダー独自の矢印キー操作はそのまま使えます。Enter または Space でドロップし、Escape で持ち上げた位置に戻します。ハンドルからフォーカスが外れた場合もドロップします。
- 読み上げ 持ち上げ、移動、ドロップ、取り消しのたびに、
sortable-status領域で項目の名前と位置を伝えます(例:「Billing, position 3 of 4.」)。この領域は、ルート要素の中、またはその直後に置くrole="status"の要素です。ページの言語で伝えるにはmessagesを渡します。 - 移動 移動するのは項目のノードそのものです。ブラウザーが
moveBefore()に対応していればそれを使うため、項目内の状態(フィールドのテキスト、再生中の動画、フォーカス)が保たれます。対応していない場合は項目を挿入し直し、ハンドルにフォーカスを戻します。 - イベント ドロップによって順序が変わると、ルート要素が
inputとchangeを発行します。返される関数のvalueは項目の順序で、各項目のdata-value、なければテキストを並べたものです。valueに代入するとその順序に並べ替えますが、イベントは発行されません。
sortable-row を指定するとリストが横並びになります。ずらす方向が水平になり、移動先を示す線は縦になります。移動には ArrowLeft と ArrowRight を使い、右から左に並ぶ場合は方向が逆になります。
ビヘイビアを適用しない場合も、リストは元の順序のまま読めます。
並べ替えリストは 1 つのリストです。ボードの段階のように、項目がリストの間も移動する場合は、カンバンを使います。
#キーボード操作
| キー | 操作 |
|---|---|
| Enter, Space | ハンドルの上で項目を持ち上げます。もう一度押すと、その位置にドロップします。 |
| ArrowUp, ArrowDown | 持ち上げた項目を 1 つ移動します。sortable-row では ArrowLeft と ArrowRight を使い、右から左に並ぶ場合は方向が逆になります。 |
| Home, End | 持ち上げた項目を先頭または末尾に移動します。 |
| Escape | 項目を、持ち上げた位置またはドラッグを始めた位置に戻します。 |
| Tab | ハンドルから移動します。項目はその位置にドロップされます。 |
#アクセシビリティ
- 各ハンドルには、移動する対象を含む名前を付けます(例:「Move Billing」)。ハンドルは項目の順序を変える唯一のコントロールですが、ドラッグだけが手段になることはありません。押すと項目が持ち上がり、ほかのハンドルを押すとそこへ移動します。ポインターでできる移動は、すべてキー操作でもできます。
- ステータス領域は、最初から空の状態でページに置いておきます。読み上げる瞬間に追加した領域は、読み上げられないことがよくあります。
- 優先度やワークフローの手順など、順序がページの動作に関わる場合は、リストの近くでそのことを説明し、新しい順序はページのほかのデータと同じ方法で保存します。
#React、Svelte、Vue
sortable コンポーネントは、保持している順序で項目を描画してビヘイビアを適用し、ビヘイビアから求められると自身のリスト内で項目を移動します。そのため、フレームワークが管理する行とページの表示が一致します。npx master-ui add sortable でプロジェクトにコピーできます。コンポーネントの構成と使い方は React、Svelte、Vue を参照してください。
#クラス
| クラス | 説明 |
|---|---|
sortable | 項目を収めるリストや積み重ねた列です。項目を運んでいる間、カーソルは握った手の形になります。 |
sortable-row | 項目を横に並べます。項目のずれと、ほかの項目が空ける場所は水平方向になります。sortable と併用します |
sortable-item | 項目です。data-value、なければテキストを値とします。運んでいる間は、端から少しはみ出す浮き上がったシートの上に持ち上がり、ポインターに追従します。 |
sortable-item-back | 運んでいる項目を末尾方向へ動かしたとき、ドラッグ中にビヘイビアが、その項目の元の位置と移動先の間にある項目に設定します。各項目は --sortable-size の分だけ先頭方向へ滑るように移動します。sortable-item と併用します |
sortable-item-forward | 運んでいる項目を先頭方向へ動かしたとき、ドラッグ中にビヘイビアが設定します。通過された各項目は --sortable-size の分だけ末尾方向へ滑るように移動します。sortable-item と併用します |
sortable-handle | 項目を運ぶためのボタンで、グリップアイコンを入れます。移動する対象を名前に含めます。操作領域は 24×28px で、タッチ画面では 44px です。 |
sortable-status | 持ち上げ、移動、ドロップのたびに内容を伝える領域です。ルート要素の中、またはその直後に置きます。スペースは占有しません。 |
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--sortable-offset | 運んでいる項目の、リストに沿った元の位置からの距離。スクリプトが書き込みます。 | |
--sortable-size | ドラッグ中にルート要素に設定されます。運んでいる項目の大きさにその後ろの間隔を加えた値で、ほかの項目が場所を空ける距離です。スクリプトが書き込みます。 | |
--sortable-radius | var(--radius-control) | 運んでいる項目が乗るシートの角の丸み |
#関連コンポーネント
- リスト画像やアイコン、テキスト、末尾の要素を並べた行の一覧。
- カード背景面から浮き上がり、割り当てられたスペースに合わせて内部のレイアウトが変わるシート。
- スワイプ行を横にスライドすると、その行で使える操作が表示されます。
- カンバン列を並べたボード。ドラッグ、キー操作、または移動先の選択で、項目を列の中や別の列へ移動できます。