# SortableList Let people arrange rows in their preferred order using a drag handle, the keyboard or move buttons. [Interactive guide](/docs/components/sortablelist) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use SortableList when rearranging records is itself a product action. ### How to compose it Keep the order in application state and save the order from onReorder. Use stable IDs and provide a click or tap alternative when appropriate. ### What to verify Reorder the same row with keyboard and touch, then verify the saved order and focus are correct. ## Usage ```tsx import { SortableList, SimpleSortableList, type SortableItem } from 'wss3-forge' ``` - Keep the order in state and apply the array received by onReorder. Give each record a stable id and provide a short label for rows containing custom content. - Drag the leading handle to reorder. On a touch screen, swipe the row content to scroll. With keyboard focus on the handle, use Arrow Up or Arrow Down to move one place, or Home or End to move to either end. - Enable showMoveButtons to support reordering with a click or tap. For an editable list, enable removable and remove the matching id in onRemove. - Use SimpleSortableList for an array of strings. Its onReorder returns strings and its onRemove receives the current row index. ```tsx import { useState } from 'react' import { SortableList, type SortableItem } from 'wss3-forge' export default function Checklist() { const [items, setItems] = useState([ { id: 'review', content: 'Review changes' }, { id: 'publish', content: 'Publish release' }, ]) return } ``` ## Runnable examples ### Release checklist ```tsx import { useState } from 'react' import { Box, SortableList, type SortableItem } from 'wss3-forge' const initialTasks: SortableItem[] = [ { id: 'review', content: 'Review changes' }, { id: 'preview', content: 'Check preview' }, { id: 'publish', content: 'Publish release' }, ] function ReleaseChecklist() { const [items, setItems] = useState(initialTasks) return ( ) } export default function Example() { return () } ``` ### Move and remove ```tsx import { useState } from 'react' import { Box, Button, SortableList, Text, VStack, type SortableItem } from 'wss3-forge' const initialTasks: SortableItem[] = [ { id: 'review', content: 'Review changes' }, { id: 'preview', content: 'Check preview' }, { id: 'publish', content: 'Publish release' }, ] function EditableChecklist() { const [items, setItems] = useState(initialTasks) return ( setItems(current => current.filter(item => item.id !== id))} /> {items.length === 0 && The checklist is empty.} {items.length < initialTasks.length && ( )} ) } export default function Example() { return () } ``` ### Reorder strings ```tsx import { useState } from 'react' import { Box, SimpleSortableList } from 'wss3-forge' function PriorityList() { const [items, setItems] = useState(['Performance', 'Accessibility', 'Localization']) return ( ) } export default function Example() { return () } ``` ## Root package API ### SortableList Let people arrange rows in their preferred order using a drag handle, the keyboard or move buttons. Props type: `SortableListProps` - `items` — `SortableItem[]` - `onReorder` — `(items: SortableItem[]) => void` - `onRemove?` — `(id: string) => void` - `renderItem?` — `(item: SortableItem, index: number) => ReactNode` - `handle?` — `boolean` Default `true`. - `removable?` — `boolean` Default `false`. - `showMoveButtons?` — `boolean` Default `false`. Show separate move buttons for pointer and touch users. - `disabled?` — `boolean` Default `false`. - `gap?` — `number` Default `8`. - `aria-label?` — `string` - `aria-labelledby?` — `string` - `className?` — `string` - `style?` — `React.CSSProperties` ### SimpleSortableList Props type: `SimpleSortableListProps` - `items` — `string[]` - `onReorder` — `(items: string[]) => void` - `onRemove?` — `(index: number) => void` - `removable?` — `boolean` - `disabled?` — `boolean` - `showMoveButtons?` — `boolean` - `aria-label?` — `string` - `aria-labelledby?` — `string` - `className?` — `string` - `style?` — `React.CSSProperties` ## Related types ```ts export interface SortableItem { id: string content: ReactNode label?: string disabled?: boolean } export interface SortableListProps { items: SortableItem[] onReorder: (items: SortableItem[]) => void onRemove?: (id: string) => void renderItem?: (item: SortableItem, index: number) => ReactNode handle?: boolean removable?: boolean /** Show separate move buttons for pointer and touch users. */ showMoveButtons?: boolean disabled?: boolean gap?: number 'aria-label'?: string 'aria-labelledby'?: string className?: string style?: React.CSSProperties } export interface SimpleSortableListProps { items: string[] onReorder: (items: string[]) => void onRemove?: (index: number) => void removable?: boolean disabled?: boolean showMoveButtons?: boolean 'aria-label'?: string 'aria-labelledby'?: string className?: string style?: React.CSSProperties } ```