adopted-ember-addons /ember-sortable
Sortable UI primitives for Ember.js
★ 298⑂ 161👁 15⑃ 473● 222▤ 65
+0
日增长
298
stars
161
forks
15
watchers
473
prs
222
issues
65
releases
README
ember-sortable
Sortable UI primitives for Ember.
Check out the demo
Requirements
| Ember Sortable | Ember | Node |
|----------------|-------|------|
| 3.0.0 | 3.24+ | 12+ |
| 4.0.0 | 3.24+ | 14+ |
| 5.0.0 | 3.28+ | n/a[^1] |
[^1]: Node is not relevant for v2 addons. As of v5.0.0, ember-sortable is a v2 addon. V2 addons don't have to be for browser-only contexts, but ember-sortable is -- so node is not relevant anymore. This is different from v1 addons, which are not browser libraries, but node programs that happen emit browser code to the consuming app at app-build time.
Installation
sh
$ ember install ember-sortable
Usage
hbs
{{! app/components/my-list/template.hbs }}
{{each this.items as |item|}}
{{item}}
↕
{{/each}}
The last dragged item was: {{this.lastDragged}}
The onChange action is called with two arguments:
- Your item models in their new order
- The model you just dragged
js
// app/components/my-list/component.js
export default class MyList extends Component {
@tracked lastDragged;
@tracked items = ['Coal Ila', 'Askaig', 'Bowmore'];
@action
reorderItems(itemModels, draggedModel) {
this.items = itemModels;
this.lastDragged = draggedModel;
}
}
The modifier version does not support groupModel, use the currying of action or the fn helper.
hbs
{{! app/components/my-list/template.hbs }}
{{each this.items as |item|}}
{{item}}
↕
{{/each}}
Changing sort direction
To change sort direction, define direction on sortable-group
Possible values are:
- y (default): allowes to move items up/down
- x: allowes to move items left/right
- grid: items can be moved in all directions inside a group
hbs
Changing spacing between currently dragged element and the rest of the group
When user starts to drag element, other elements jump back. Works for all direction option.
In y case: elements above current one jump up, and elements below current one - jump down.
In x / grid case: elements before current one jump to the left, and elements after current one - jump to the right.
To change this property, define spacing on sortable-item (default is 0):
hbs
Changing the drag tolerance
distance attribute changes the tolerance, in pixels, for when sorting should start.
If specified, sorting will not start until after mouse is dragged beyond distance.
Can be used to allow for clicks on elements within a handle.
hbs
Disabling reordering
The disabled attribute allows you to disable sorting for the entire group and its child items.
hbs
CSS, Animation
Sortable items can be in one of four states: default, dragging, dropping, and activated.
The classes look like this:
html
...
...
...
...
In our example app.css we apply a
transition of .125s in the default case:
css
.sortable-item {
transition: all 0.125s;
}
While an item is dragging we want it to move pixel-for-pixel with the
user’s mouse so we bTop issues
#654Given the number of issues there are with sorting / re-ordering / managing multiple lists, how do the users of ember-sortable feel about the internals of ember-sortable being built on a more well-established sorting library (vanilla js)15 comments · 2025-11-02#3562.2.0: massive bundle size increase7 comments · 2020-02-10#339Drag-drop/clicks don't work with nested components7 comments · 2019-12-06#184Offset is incorrect with table in firefox6 comments · 2018-07-30#291Improve documentation and Integrate automated code docs5 comments · 2019-10-25#516Bug when using two mouse connected3 comments · 2023-05-10#481Ember-sortable 4.0.0 crashes during build on ember-modifier3 comments · 2022-07-05#359Support for nested sortable-group items.3 comments · 2020-02-18
Latest release
v5.5.0 v5.5.0 2026-11-09Release (2026-11-09) ember-sortable 5.5.0 (minor) :rocket: Enhancement ember-sortable 691 Assign the item state directly instead of with set() (@johanrd) 690 Declare the modifiers' actions as arrow functions (@johanrd) :bug: Bug Fix ember-sortable 693 Only drag on auto scroll when the container scrolled (@johanrd) 688 Recompute firstItemPosition, and drop the last @computed (@johanrd) :memo: Documentation 689 Use a plain array in the autoscroll demo (@johanrd) Committers: 1 - Johan Røed (@johanrd)