Communitygithub.com

ドラッグ&ドロップ

dnd-kitを使用したソート可能なリスト、カンバンボード、ファイルドロップゾーン。タッチサポートとアクセシビリティ対応。

ドラッグ&ドロップ とは?

このスキルは、最新のアクセシブルなドラッグ&ドロップライブラリである dnd-kit を使用して、SortableList、カンバンボード、ファイルドロップゾーンなどの DnD 機能を実装するためのパターンとルールを提供します。 SortableContext と useSortable フックを使ったソート可能なリスト、複数の SortableContext を組み合わせたカンバンボード、react-dropzone やネイティブイベントを使ったファイルドロップゾーンの実装方法を網羅しています。 dnd-kit はタッチ操作やキーボード操作をネイティブでサポートしており、TouchSensor、PointerSensor(アクティベーション制約付き)、KeyboardSensor を活用することで、あらゆるユーザーに対してアクセシブルな DnD 体験を提供できます。 オプティミスティックな並べ替え(即時UI更新→バックグラウンドで永続化→エラー時にロールバック)や DragOverlay による視覚的なフィードバックも推奨されています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/drag-and-drop

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

ドラッグ&ドロップ は何をしますか?

ルール

  • @dnd-kit/core + @dnd-kit/sortable を使用 — モダンでアクセシブル、タッチ操作に対応した DnD ライブラリ
  • ソート可能なリスト: <SortableContext> でラップし、各アイテムで useSortable() フックを使用
  • カンバンボード: 1つの <DndContext> 内に複数の <SortableContext> コンテナ(カラムごとに1つ)を配置
  • ファイルドロップゾーン: react-dropzone またはネイティブの onDragOver / onDrop と e.dataTransfer.files を使用
  • タッチサポート: dnd-kit がタッチをネイティブに処理 — アクティベーション制約付きの TouchSensor および PointerSensor を使用
  • アクセシビリティ: dnd-kit はキーボード DnD を標準で提供 — sortableKeyboardCoordinates と組み合わせた KeyboardSensor を使用
  • オプティミスティックな並べ替え: ドロップ時に即座に状態を更新、バックグラウンドでサーバーに永続化、エラー時にはロールバック
  • ドラッグオーバーレイ: <DragOverlay> を使用してドラッグ中のアイテムの浮動プレビューを表示 — より良い視覚的フィードバック

パターン

import { DndContext, closestCenter, DragOverlay } from "@dnd-kit/core";
import { SortableContext, verticalListSortingStrategy, useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";

function SortableItem({ id, children }: { id: string; children: React.ReactNode }) {
  const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
  const style = { transform: CSS.Transform.toString(transform), transition };
  return (
    <div ref={setNodeRef} style={style} {...attributes} {...listeners}>
      {children}
    </div>
  );
}

function SortableList({ items }: { items: Item[] }) {
  const [activeId, setActiveId] = useState<string | null>(null);
  return (
    <DndContext
      collisionDetection={closestCenter}
      onDragStart={({ active }) => setActiveId(active.id)}
      onDragEnd={handleDragEnd}
    >
      <SortableContext items={items.map((i) => i.id)} strategy={verticalListSortingStrategy}>
        {items.map((item) => (
          <SortableItem key={item.id} id={item.id}>{item.name}</SortableItem>
        ))}
      </SortableContext>
      <DragOverlay>{activeId ? <ItemPreview id={activeId} /> : null}</DragOverlay>
    </DndContext>
  );
}

避けるべきこと

  • HTML5 のドラッグ API を直接使用する — タッチ/モバイル/アクセシビリティのサポートが不十分
  • キーボードアクセシビリティを忘れる — 常に KeyboardSensor を含める
  • ドラッグ中に状態を変更する — onDragEnd でのみ更新
  • DragOverlay を省略する — これがないと、ドラッグ中に元のアイテムが視覚的フィードバックなしで消えてしまう

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

関連スキル