Skip to content

Drag & Drop Plugin

The drag-drop plugin allows users to reorder selected items by dragging them. This is useful when the order of selections matters, such as priority lists or ranked preferences.

Usage

Behavior

  • Selected items display a drag handle on hover
  • Click and drag an item to reorder it among the other selected items
  • The underlying <select> element's option order is updated to match
  • The ds:change event fires after reordering with the new order reflected in the value array

Configuration

AttributeDescriptionDefault
data-plugin-drag-drop-handleShow a dedicated drag handle icontrue
data-plugin-drag-drop-animationEnable smooth animation during dragtrue

Reading the Order

The value array reflects the current visual order:

js
const select = DotSelect.getInstance(document.querySelector('#priority-list'));
const orderedValues = select.getValue();
// ["2", "1", "3"] — reflects the user's drag-and-drop order

Styling

Customize the drag handle and drag state:

css
.dot-select .ds-item-drag-handle {
  cursor: grab;
  color: #94a3b8;
  margin-right: 4px;
}

.dot-select .ds-item.dragging {
  opacity: 0.5;
  background-color: #f1f5f9;
}

.dot-select .ds-item.drag-over {
  border-top: 2px solid #3b82f6;
}

Accessibility

  • Drag and drop is supplemented with keyboard controls: use Alt + Arrow Up/Down to reorder items
  • The drag handle has an aria-label of "Drag to reorder"
  • Screen readers announce the item's new position after reordering

TIP

Combine drag-drop with the remove-button plugin for a complete experience where users can both reorder and remove items.

MIT Licensed