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:changeevent fires after reordering with the new order reflected in the value array
Configuration
| Attribute | Description | Default |
|---|---|---|
data-plugin-drag-drop-handle | Show a dedicated drag handle icon | true |
data-plugin-drag-drop-animation | Enable smooth animation during drag | true |
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 orderStyling
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/Downto reorder items - The drag handle has an
aria-labelof "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.