@bluecateng/smooth-reorder
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

@bluecateng/smooth-reorder GitHub license npm version

Allows reordering a list with either mouse dragging or keyboard using only vanilla JS. Elements are moved with CSS transitions where possible or with @bluecateng/nano-spring, so it feels more natural. The callbacks allow implementation of feedback for accessibility.

The article 4 Major Patterns for Accessible Drag and Drop / Sorting a List in Medium has an example of how to implement accessibility.

Size: 4,090 bytes before compression.

Installation

npm i -S @bluecateng/smooth-reorder

Example

import reorder from '@bluecateng/smooth-reorder';

const container = document.querySelector('#test');
reorder(container, {
	onStart: (element, position) => console.log(`Started moving element ${element} from ${position}`),
	onMove: (element, position) => console.log(`Element ${element} moved to ${position}`),
	onFinish: (element) => console.log(`Element ${element} moved`),
	onCancel: (element) => console.log(`Element ${element} move cancelled`),
});

This CSS must be added to the page:

.draggable {
	cursor: move;
	cursor: grab;
	touch-action: none;
}
.dragging {
	z-index: 1000;
}
.placeholder {
	opacity: 0;
}
.clone {
	position: absolute;
	left: 0;
	top: 0;
	will-change: transform;
}

Output

Output

Readme

Keywords

Package Sidebar

Install

npm i @bluecateng/smooth-reorder

Weekly Downloads

508

Version

2.1.0

License

ISC

Unpacked Size

8.72 kB

Total Files

5

Last publish

Collaborators

  • jcestibariz
  • chinanwu