TBX Docs
ExercisesCatalogue

SortList

Drag and drop to arrange items in the correct order

SortList renders a shuffled list of items and lets users drag and drop to arrange them in the correct order. It uses @dnd-kit/react for accessible drag and drop interactions.

Import

import { SortList } from '@bside-tech/tbx-ui/components';

Example

Sort List
Put the items in the correct order by dragging.
  • First step
  • Second step
  • Third step
  • Fourth step
<SortList
  items={[
    'First step',
    'Second step',
    'Third step',
    'Fourth step',
  ]}
  variant="column"
/>

Props

Prop

Type

Labels

Override labels via the labels prop. Supported keys: check, reset (action buttons), results (e.g. "correct" in "3 / 5 correct").

<SortList
  items={['First', 'Second', 'Third']}
  labels={{
    check: 'Verify order',
    reset: 'Shuffle again',
    results: 'correct',
  }}
/>

Style

Tailwind v4 is available for customisations. Pass classes via the classNames prop, or override CSS variables for fine-grained control.

CSS Classes

KeyElement
rootRoot wrapper
listList container
itemSortable item
checkButtonCheck button
resetButtonReset button
resultResults text

CSS Variables

Scoped under .tbx-sortlist:

VariablePurpose
--sortlist-item-bgItem background
--sortlist-item-borderItem border
--sortlist-item-draggingItem background when dragging
--sortlist-action-bg, --sortlist-action-borderCheck/Reset button background and border
--sortlist-result-neutral, --sortlist-result-correct, --sortlist-result-wrongResults text colors (neutral, correct, wrong)
--sortlist-correct-bg, --sortlist-correct-borderItem when correct
--sortlist-wrong-bg, --sortlist-wrong-borderItem when wrong

These feed into --exercise-action-bg, --exercise-action-border and --exercise-result-* used by ExerciseLayout.

Item labels use --exercise-layout-content-font-size.

Variants

Column (default)

Items are stacked vertically. Ideal for ordered lists like steps or rankings.

Sort List
Put the items in the correct order by dragging.
  • Prepare ingredients
  • Mix the dough
  • Shape and bake
  • Cool and serve
<SortList
  items={[
    'Prepare ingredients',
    'Mix the dough',
    'Shape and bake',
    'Cool and serve',
  ]}
  variant="column"
/>

Row

Items are arranged horizontally. Use for short labels or categories.

Sort List
Put the items in the correct order by dragging.
  • Smallest
  • Small
  • Medium
  • Large
  • Largest
<SortList
  items={['Smallest', 'Small', 'Medium', 'Large', 'Largest']}
  variant="row"
/>

Hook

Use useSortListExercise when building custom sort interfaces:

import { useSortListExercise } from '@bside-tech/tbx-ui/hooks';

const { order, reorder, setOrder, isCorrect, check, reset } = useSortListExercise({
  itemCount: 5,
  checkOn: 'manual',
});
ReturnDescription
orderCurrent order: order[i] = original index at position i
reorderMove item from old index to new index
setOrderSet full order (e.g. for shuffle)
isCorrectnull = not validated, true/false = result
checkValidate current order
resetReset with optional initial order

On this page