Skip to content

Commit 29fc641

Browse files
committed
[Bugfix] Use deregisterItem instead of registerItem on destroy
[Feature] Adding isDraggingDisabled flag to allow specifying a sortable-item to be non-sortable
1 parent f0149eb commit 29fc641

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ export default Ember.Route.extend({
212212
{{/sortable-item}}
213213
```
214214

215+
### Disabling Drag (Experimental)
216+
`sortable-item` exposes an optional `isDraggingDisabled` flag that you can use to disable `drag` on the particular item.
217+
This flag is intended as an utility to make your life easier with 3 main benefits:
218+
1. You can now specify which `sortable-item` are not intended to be draggable/sortable.
219+
2. You do not have to duplicate the `sortable-item` UI just for the purpose of disabling the `sorting` behavior.
220+
3. Allows you to access the entire list of `models` for your `onChange` action, which can now be a mix of sortable and non-sortable items.
221+
215222
### Data down, actions up
216223

217224
No data is mutated by `sortable-group` or `sortable-item`. In the spirit of “data down, actions up”, a fresh array containing the models from each item in their new order is sent via the group’s `onChange` action.

addon/components/sortable-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ export default Component.extend({
705705
},
706706

707707
deregisterItem(item) {
708-
this._registerItem(item);
708+
this._deregisterItem(item);
709709
},
710710

711711
setSelectedItem(item) {

addon/components/sortable-item.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ export default Component.extend({
133133
*/
134134
spacing: 0,
135135

136+
/**
137+
Removes the ability for the current item to be dragged
138+
@property isDraggingDisabled
139+
@type Boolean
140+
@default false
141+
*/
142+
isDraggingDisabled: false,
143+
136144
/**
137145
@private
138146
Allows host instance to use the `group` property for something else with
@@ -251,6 +259,11 @@ export default Component.extend({
251259
* @private
252260
*/
253261
_primeDrag(startEvent) {
262+
// Prevent dragging if the sortable-item is disabled.
263+
if (this.get('isDraggingDisabled')) {
264+
return;
265+
}
266+
254267
let handle = this.get('handle');
255268

256269
if (handle && !startEvent.target.closest(handle)) {

0 commit comments

Comments
 (0)