ember-sortable 2.2.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +2 -2
- package/.github/workflows/github_ci.yml +15 -13
- package/.huskyrc +0 -1
- package/CHANGELOG.md +234 -104
- package/MIGRATION_GUIDE_MODIFIERS.md +20 -13
- package/MIGRATION_GUIDE_V2.md +20 -8
- package/README.md +83 -149
- package/V2_MIGRATION_RFC.md +188 -222
- package/addon/modifiers/sortable-group.js +59 -52
- package/addon/modifiers/sortable-handle.js +16 -18
- package/addon/modifiers/sortable-item.js +124 -84
- package/addon/services/ember-sortable.js +3 -6
- package/addon/system/scroll-parent.js +1 -1
- package/addon/utils/coordinate.js +1 -1
- package/addon/utils/css-calculation.js +2 -2
- package/addon/utils/defaults.js +4 -3
- package/addon/utils/keyboard.js +3 -12
- package/addon-test-support/helpers/drag.js +3 -11
- package/addon-test-support/helpers/index.js +1 -4
- package/addon-test-support/helpers/reorder.js +4 -6
- package/addon-test-support/utils/keyboard.js +3 -12
- package/addon-test-support/utils/offset.js +6 -6
- package/config/environment.js +2 -2
- package/index.js +0 -20
- package/package.json +32 -18
- package/addon/components/sortable-group.js +0 -726
- package/addon/components/sortable-handle.js +0 -11
- package/addon/components/sortable-item.js +0 -753
- package/addon/styles/components/sortable-group.css +0 -9
- package/addon/templates/components/sortable-group.hbs +0 -16
- package/addon/templates/components/sortable-handle.hbs +0 -1
- package/addon/templates/components/sortable-item.hbs +0 -2
- package/addon/utils/transitionend.js +0 -22
- package/app/components/sortable-group.js +0 -3
- package/app/components/sortable-handle.js +0 -4
- package/app/components/sortable-item.js +0 -3
- package/jsconfig.json +0 -1
- package/vendor/polyfills/closest.js +0 -21
|
@@ -5,16 +5,20 @@
|
|
|
5
5
|
To use modifiers, you must use angle-bracket syntax
|
|
6
6
|
|
|
7
7
|
### New Root component
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
1. Instead of using `sortable-group` as a component, use `sortable-group` as a modifier
|
|
10
|
+
any element. You no longer need to tell `sortable-group` about the models, so the `each`
|
|
11
|
+
uses the models directly.
|
|
11
12
|
|
|
12
13
|
**Old Component**
|
|
14
|
+
|
|
13
15
|
```hbs
|
|
14
16
|
{{#sortable-group model=model.items onChange=(action "reorderItems") as |group|}}
|
|
15
17
|
{{#each group.model as |item|}}
|
|
16
18
|
```
|
|
19
|
+
|
|
17
20
|
**New Component**
|
|
21
|
+
|
|
18
22
|
```hbs
|
|
19
23
|
<ol {{sortable-group onChange=(action "reorderItems")}}>
|
|
20
24
|
{{#each model.items as |item|}}
|
|
@@ -23,19 +27,21 @@ uses the models directly.
|
|
|
23
27
|
2. Each `item` can be represented by any dom element or component using angle-bracket syntax
|
|
24
28
|
|
|
25
29
|
**Old Component**
|
|
30
|
+
|
|
26
31
|
```hbs
|
|
27
|
-
{{#sortable-group model=model.items onChange=(action
|
|
32
|
+
{{#sortable-group model=model.items onChange=(action 'reorderItems') as |group|}}
|
|
28
33
|
{{#each group.model as |item|}}
|
|
29
34
|
{{#group.item model=item}}
|
|
30
|
-
|
|
35
|
+
{{tem.name}}
|
|
31
36
|
{{/group.item}}
|
|
32
37
|
{{/each}}
|
|
33
38
|
{{/sortable-group}}
|
|
34
39
|
```
|
|
35
40
|
|
|
36
41
|
**New Component with modifier**
|
|
42
|
+
|
|
37
43
|
```hbs
|
|
38
|
-
<ol {{sortable-group onChange=(action
|
|
44
|
+
<ol {{sortable-group onChange=(action 'reorderItems')}}>
|
|
39
45
|
{{#each model.items as |item|}}
|
|
40
46
|
<li {{sortable-item model=item}}>
|
|
41
47
|
{{tem.name}}
|
|
@@ -47,6 +53,7 @@ uses the models directly.
|
|
|
47
53
|
3. The Handle is also any element with a `sortable-handle` applied to it.
|
|
48
54
|
|
|
49
55
|
**Old Component**
|
|
56
|
+
|
|
50
57
|
```hbs
|
|
51
58
|
{{#sortable-group model=model.items onChange=(action "reorderItems") as |group|}}
|
|
52
59
|
{{#each group.model as |modelItem|}}
|
|
@@ -61,28 +68,28 @@ uses the models directly.
|
|
|
61
68
|
```
|
|
62
69
|
|
|
63
70
|
**New Component with modifier**
|
|
71
|
+
|
|
64
72
|
```hbs
|
|
65
|
-
<ol {{sortable-group onChange=(action
|
|
73
|
+
<ol {{sortable-group onChange=(action 'reorderItems')}}>
|
|
66
74
|
{{#each model.items as |item|}}
|
|
67
75
|
<li {{sortable-item model=item}}>
|
|
68
76
|
{{tem.name}}
|
|
69
|
-
<span class=
|
|
77
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
70
78
|
</li>
|
|
71
79
|
{{/each}}
|
|
72
80
|
</ol>
|
|
73
81
|
```
|
|
74
82
|
|
|
75
|
-
4. The modifier `groupModel` property is no longer supported. The equivalent can
|
|
76
|
-
be accomplished by the `action` helper or the new `fn` helper.
|
|
83
|
+
4. The modifier `groupModel` property is no longer supported. The equivalent can
|
|
84
|
+
be accomplished by the `action` helper or the new `fn` helper.
|
|
77
85
|
|
|
78
86
|
```hbs
|
|
79
|
-
<ol {{sortable-group onChange=(action
|
|
87
|
+
<ol {{sortable-group onChange=(action 'reorderItems' model)}}>
|
|
80
88
|
{{#each model.items as |item|}}
|
|
81
89
|
<li {{sortable-item model=item}}>
|
|
82
90
|
{{tem.name}}
|
|
83
|
-
<span class=
|
|
91
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
84
92
|
</li>
|
|
85
93
|
{{/each}}
|
|
86
94
|
</ol>
|
|
87
95
|
```
|
|
88
|
-
|
package/MIGRATION_GUIDE_V2.md
CHANGED
|
@@ -5,16 +5,20 @@
|
|
|
5
5
|
[High Order Components](#Higher Order Components) or [Modifiers](/MIGRATION_GUIDE_MODIFIERS.md)
|
|
6
6
|
|
|
7
7
|
### Higher Order Components
|
|
8
|
+
|
|
8
9
|
`Ember-sortable` can now be built using [higher order components](https://v4.chriskrycho.com/2018/higher-order-components-in-emberjs.html)
|
|
9
10
|
|
|
10
11
|
1. The array of models are now yielded out by `sortable-group`
|
|
11
12
|
|
|
12
13
|
**V1**
|
|
14
|
+
|
|
13
15
|
```hbs
|
|
14
16
|
{{#sortable-group onChange=(action "reorderItems") as |group|}}
|
|
15
17
|
{{#each model.items as |item|}}
|
|
16
18
|
```
|
|
19
|
+
|
|
17
20
|
**V2**
|
|
21
|
+
|
|
18
22
|
```hbs
|
|
19
23
|
{{#sortable-group model=model.items onChange=(action "reorderItems") as |group|}}
|
|
20
24
|
{{#each group.model as |item|}}
|
|
@@ -23,23 +27,25 @@
|
|
|
23
27
|
2. Each `item` can be represented by the yielded `sortable-item` instead of directly using `sortable-item` and passing the `group` manually.
|
|
24
28
|
|
|
25
29
|
**V1**
|
|
30
|
+
|
|
26
31
|
```hbs
|
|
27
|
-
{{#sortable-group onChange=(action
|
|
32
|
+
{{#sortable-group onChange=(action 'reorderItems') as |group|}}
|
|
28
33
|
{{#each model.items as |item|}}
|
|
29
|
-
{{#sortable-item model=item group=group handle=
|
|
34
|
+
{{#sortable-item model=item group=group handle='.handle'}}
|
|
30
35
|
{{item.name}}
|
|
31
|
-
<span class=
|
|
36
|
+
<span class='handle'>↕</span>
|
|
32
37
|
{{/sortable-item}}
|
|
33
38
|
{{/each}}
|
|
34
39
|
{{/sortable-group}}
|
|
35
40
|
```
|
|
36
41
|
|
|
37
42
|
**V2**
|
|
43
|
+
|
|
38
44
|
```hbs
|
|
39
|
-
{{#sortable-group model=model.items onChange=(action
|
|
45
|
+
{{#sortable-group model=model.items onChange=(action 'reorderItems') as |group|}}
|
|
40
46
|
{{#each group.model as |item|}}
|
|
41
47
|
{{#group.item model=item}}
|
|
42
|
-
|
|
48
|
+
...
|
|
43
49
|
{{/group.item}}
|
|
44
50
|
{{/each}}
|
|
45
51
|
{{/sortable-group}}
|
|
@@ -48,18 +54,20 @@
|
|
|
48
54
|
3. It is recommended to use the yielded `sortable-handle` instead of referencing `handle` by `class`, as it guarantees accessibility support.
|
|
49
55
|
|
|
50
56
|
**V1**
|
|
57
|
+
|
|
51
58
|
```hbs
|
|
52
|
-
{{#sortable-group onChange=(action
|
|
59
|
+
{{#sortable-group onChange=(action 'reorderItems') as |group|}}
|
|
53
60
|
{{#each model.items as |item|}}
|
|
54
|
-
{{#sortable-item model=item group=group handle=
|
|
61
|
+
{{#sortable-item model=item group=group handle='.handle'}}
|
|
55
62
|
{{item.name}}
|
|
56
|
-
<span class=
|
|
63
|
+
<span class='handle'>↕</span>
|
|
57
64
|
{{/sortable-item}}
|
|
58
65
|
{{/each}}
|
|
59
66
|
{{/sortable-group}}
|
|
60
67
|
```
|
|
61
68
|
|
|
62
69
|
**V2**
|
|
70
|
+
|
|
63
71
|
```hbs
|
|
64
72
|
{{#sortable-group model=model.items onChange=(action "reorderItems") as |group|}}
|
|
65
73
|
{{#each group.model as |modelItem|}}
|
|
@@ -76,6 +84,7 @@
|
|
|
76
84
|
4. `groupModel` is still supported via `groupModel` instead of `model`
|
|
77
85
|
|
|
78
86
|
**V1**
|
|
87
|
+
|
|
79
88
|
```hbs
|
|
80
89
|
{{#sortable-group model=model onChange=(action "reorderItems") as |group|}}
|
|
81
90
|
{{#each model.items as |item|}}
|
|
@@ -84,6 +93,7 @@
|
|
|
84
93
|
```
|
|
85
94
|
|
|
86
95
|
**V2**
|
|
96
|
+
|
|
87
97
|
```hbs
|
|
88
98
|
{{#sortable-group groupModel=model model=model.items onChange=(action "reorderItems") as |group|}}
|
|
89
99
|
{{#each group.model as |item|}}
|
|
@@ -94,6 +104,7 @@
|
|
|
94
104
|
### Modifiers
|
|
95
105
|
|
|
96
106
|
### Accessibility support
|
|
107
|
+
|
|
97
108
|
1. Keyboard navigation is built into `ember-sortable`.
|
|
98
109
|
2. `a11yItemName`, `a11yAnnouncementConfig`, `itemVisualClass`, `handleVisualClass` can be supplied to enhance the accessibility experience.
|
|
99
110
|
3. Refer to [Accessibility Section](/README.md#Accessibility) for more details.
|
|
@@ -103,6 +114,7 @@
|
|
|
103
114
|
```
|
|
104
115
|
|
|
105
116
|
### Testing
|
|
117
|
+
|
|
106
118
|
1. The `drag` and `reorder` test helpers are no longer global `async` helpers. They are now importable.
|
|
107
119
|
|
|
108
120
|
Refer to [Testing Section](/README.md#Testing) for more details.
|
package/README.md
CHANGED
|
@@ -12,10 +12,13 @@ Sortable UI primitives for Ember.
|
|
|
12
12
|
|
|
13
13
|
[Check out the demo](https://adopted-ember-addons.github.io/ember-sortable/demo/)
|
|
14
14
|
|
|
15
|
-
##
|
|
16
|
-
|
|
15
|
+
## v2 -> v3 Migration
|
|
16
|
+
|
|
17
|
+
The component versions have been removed and you must use the modifier.
|
|
18
|
+
The modifier version does not support `groupModel`, use the currying of the `fn` helper.
|
|
17
19
|
|
|
18
20
|
## v1 -> v2 Migration
|
|
21
|
+
|
|
19
22
|
If you are migrating from `1.x.x` to `2.x.x`,
|
|
20
23
|
For components, please read this [migration guide](/MIGRATION_GUIDE_V2.md).
|
|
21
24
|
For modifiers, please read this [migration guide](/MIGRATION_GUIDE_MODIFIERS.md).
|
|
@@ -38,31 +41,14 @@ $ ember install ember-sortable
|
|
|
38
41
|
|
|
39
42
|
## Usage
|
|
40
43
|
|
|
41
|
-
### component
|
|
42
|
-
```hbs
|
|
43
|
-
{{! app/templates/my-route.hbs }}
|
|
44
|
-
|
|
45
|
-
{{#sortable-group model=model.items onChange=(action "reorderItems") as |group|}}
|
|
46
|
-
{{#each group.model as |modelItem|}}
|
|
47
|
-
{{#group.item model=modelItem as |item|}}
|
|
48
|
-
{{modelItem.name}}
|
|
49
|
-
{{#item.handle}}
|
|
50
|
-
<span class="handle">↕</span>
|
|
51
|
-
{{/item.handle}}
|
|
52
|
-
{{/group.item}}
|
|
53
|
-
{{/each}}
|
|
54
|
-
{{/sortable-group}}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### modifier
|
|
58
44
|
```hbs
|
|
59
45
|
{{! app/templates/my-route.hbs }}
|
|
60
46
|
|
|
61
|
-
<ol {{sortable-group onChange=
|
|
62
|
-
{{#each model.items as |modelItem|}}
|
|
47
|
+
<ol {{sortable-group onChange=this.reorderItems}}>
|
|
48
|
+
{{#each @model.items as |modelItem|}}
|
|
63
49
|
<li {{sortable-item model=modelItem}}>
|
|
64
50
|
{{modelItem.name}}
|
|
65
|
-
<span class=
|
|
51
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
66
52
|
</li>
|
|
67
53
|
{{/each}}
|
|
68
54
|
</ol>
|
|
@@ -76,46 +62,13 @@ The `onChange` action is called with two arguments:
|
|
|
76
62
|
```js
|
|
77
63
|
// app/routes/my-route.js
|
|
78
64
|
|
|
79
|
-
export default
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Declaring a “group model”
|
|
90
|
-
|
|
91
|
-
When `groupModel` is set on the `sortable-group`, the `onChange` action is called
|
|
92
|
-
with that group model as the first argument:
|
|
93
|
-
|
|
94
|
-
```hbs
|
|
95
|
-
{{! app/templates/my-route.hbs }}
|
|
96
|
-
|
|
97
|
-
{{#sortable-group groupModel=model model=model.items onChange=(action "reorderItems") as |group|}}
|
|
98
|
-
{{#each group.model as |modelItem|}}
|
|
99
|
-
{{#group.item model=modelItem as |item|}}
|
|
100
|
-
{{modelItem.name}}
|
|
101
|
-
{{#item.handle}}
|
|
102
|
-
<span class="handle">↕</span>
|
|
103
|
-
{{/item.handle}}
|
|
104
|
-
{{/group.item}}
|
|
105
|
-
{{/each}}
|
|
106
|
-
{{/sortable-group}}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
// app/routes/my-route.js
|
|
111
|
-
|
|
112
|
-
export default Ember.Route.extend({
|
|
113
|
-
actions: {
|
|
114
|
-
reorderItems(groupModel, itemModels, draggedModel) {
|
|
115
|
-
groupModel.set('items', itemModels);
|
|
116
|
-
}
|
|
65
|
+
export default class MyRoute extends Route {
|
|
66
|
+
@action
|
|
67
|
+
reorderItems(itemModels, draggedModel) {
|
|
68
|
+
this.currentModel.items, itemModels);
|
|
69
|
+
this.currentModel.justDragged, draggedModel);
|
|
117
70
|
}
|
|
118
|
-
}
|
|
71
|
+
}
|
|
119
72
|
```
|
|
120
73
|
|
|
121
74
|
The modifier version does not support `groupModel`, use the currying of `action` or the `fn` helper.
|
|
@@ -123,26 +76,20 @@ The modifier version does not support `groupModel`, use the currying of `action`
|
|
|
123
76
|
```hbs
|
|
124
77
|
{{! app/templates/my-route.hbs }}
|
|
125
78
|
|
|
126
|
-
<ol {{sortable-group onChange=(
|
|
127
|
-
{{#each model.items as |modelItem|}}
|
|
79
|
+
<ol {{sortable-group onChange=(fn this.reorderItems model)}}>
|
|
80
|
+
{{#each @model.items as |modelItem|}}
|
|
128
81
|
<li {{sortable-item model=modelItem}}>
|
|
129
82
|
{{modelItem.name}}
|
|
130
|
-
<span class=
|
|
83
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
131
84
|
</li>
|
|
132
85
|
{{/each}}
|
|
133
86
|
</ol>
|
|
134
87
|
```
|
|
135
88
|
|
|
136
|
-
|
|
137
89
|
### Changing sort direction
|
|
138
90
|
|
|
139
91
|
To change sort direction, define `direction` on `sortable-group` (default is `y`):
|
|
140
92
|
|
|
141
|
-
component
|
|
142
|
-
```hbs
|
|
143
|
-
{{#sortable-group direction="x" onChange=(action "reorderItems") as |group|}}
|
|
144
|
-
```
|
|
145
|
-
modifier
|
|
146
93
|
```hbs
|
|
147
94
|
<ol {{sortable-group direction="x" onChange=(action "reorderItems")}>
|
|
148
95
|
```
|
|
@@ -156,11 +103,6 @@ In `x` case: elements before current one jump to the left, and elements after cu
|
|
|
156
103
|
|
|
157
104
|
To change this property, define `spacing` on `sortable-item` (default is `0`):
|
|
158
105
|
|
|
159
|
-
component
|
|
160
|
-
```hbs
|
|
161
|
-
{{#sortable-item spacing=15}}
|
|
162
|
-
```
|
|
163
|
-
modifier
|
|
164
106
|
```hbs
|
|
165
107
|
<li {{sortable-item spacing=15}}>
|
|
166
108
|
```
|
|
@@ -171,13 +113,16 @@ modifier
|
|
|
171
113
|
If specified, sorting will not start until after mouse is dragged beyond distance.
|
|
172
114
|
Can be used to allow for clicks on elements within a handle.
|
|
173
115
|
|
|
174
|
-
component
|
|
175
116
|
```hbs
|
|
176
|
-
{{
|
|
117
|
+
<li {{sortable-item distance=30}}>
|
|
177
118
|
```
|
|
178
|
-
|
|
119
|
+
|
|
120
|
+
### Disabling reordering
|
|
121
|
+
|
|
122
|
+
The `disabled` attribute allows you to disable sorting for the entire group and its child items.
|
|
123
|
+
|
|
179
124
|
```hbs
|
|
180
|
-
<li {{sortable-
|
|
125
|
+
<li {{sortable-group disabled=true}}>
|
|
181
126
|
```
|
|
182
127
|
|
|
183
128
|
### CSS, Animation
|
|
@@ -201,7 +146,7 @@ transition of `.125s` in the default case:
|
|
|
201
146
|
|
|
202
147
|
```css
|
|
203
148
|
.sortable-item {
|
|
204
|
-
transition: all .125s;
|
|
149
|
+
transition: all 0.125s;
|
|
205
150
|
}
|
|
206
151
|
```
|
|
207
152
|
|
|
@@ -244,37 +189,22 @@ argument.
|
|
|
244
189
|
```js
|
|
245
190
|
// app/routes/my-route.js
|
|
246
191
|
|
|
247
|
-
export default
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
192
|
+
export default class MyRoute extends Route {
|
|
193
|
+
@action
|
|
194
|
+
dragStarted(item) {
|
|
195
|
+
console.log(`Item started dragging: ${item.get('name')}`);
|
|
196
|
+
},
|
|
197
|
+
@action
|
|
198
|
+
dragStopped(item) {
|
|
199
|
+
console.log(`Item stopped dragging: ${item.get('name')}`);
|
|
255
200
|
}
|
|
256
|
-
}
|
|
201
|
+
}
|
|
257
202
|
```
|
|
258
203
|
|
|
259
|
-
component
|
|
260
|
-
```hbs
|
|
261
|
-
{{#sortable-item
|
|
262
|
-
onDragStart=(action "dragStarted")
|
|
263
|
-
onDragStop=(action "dragStopped")
|
|
264
|
-
model=modelItem
|
|
265
|
-
as |item|
|
|
266
|
-
}}
|
|
267
|
-
{{modelItem.name}}
|
|
268
|
-
{{#item.handle}}
|
|
269
|
-
<span class="handle">↕</span>
|
|
270
|
-
{{/item.handle}}
|
|
271
|
-
{{/sortable-item}}
|
|
272
|
-
```
|
|
273
|
-
modifier
|
|
274
204
|
```hbs
|
|
275
205
|
<li {{#sortable-item
|
|
276
|
-
onDragStart=
|
|
277
|
-
onDragStop=
|
|
206
|
+
onDragStart=this.dragStarted
|
|
207
|
+
onDragStop=this.dragStopped
|
|
278
208
|
model=modelItem
|
|
279
209
|
}}
|
|
280
210
|
>
|
|
@@ -283,18 +213,18 @@ modifier
|
|
|
283
213
|
</li>
|
|
284
214
|
```
|
|
285
215
|
|
|
286
|
-
### Multiple Ember-Sortables renders simultaneously
|
|
216
|
+
### Multiple Ember-Sortables renders simultaneously
|
|
287
217
|
|
|
288
|
-
|
|
218
|
+
There is a service behind the scenes for communication between the group and the items and to maintain state. It does this seemlessly when the elements are rendered on the screen. However, if there are two sortables rendered at the same time, either in the same component or different components, the state management does not know which items belong to which group.
|
|
289
219
|
|
|
290
220
|
Both the `{{sortable-group}}` and `{{sortable-item}}` take an additional argument `groupName`. Should you encounter this conflict, assign a `groupName` to the group and items. You only need to do this for one of the sortables in conflict, but you can on both if you wish.
|
|
291
221
|
|
|
292
222
|
```hbs
|
|
293
|
-
<ol {{sortable-group groupName=
|
|
294
|
-
{{#each model.items as |modelItem|}}
|
|
295
|
-
<li {{sortable-item groupName=
|
|
223
|
+
<ol {{sortable-group groupName='products' onChange=this.reorderItems}}>
|
|
224
|
+
{{#each @model.items as |modelItem|}}
|
|
225
|
+
<li {{sortable-item groupName='products' model=modelItem}}>
|
|
296
226
|
{{modelItem.name}}
|
|
297
|
-
<span class=
|
|
227
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
298
228
|
</li>
|
|
299
229
|
{{/each}}
|
|
300
230
|
</ol>
|
|
@@ -303,22 +233,24 @@ Both the `{{sortable-group}}` and `{{sortable-item}}` take an additional argumen
|
|
|
303
233
|
Ensure that the same name is passed to both the group and the items, this would be best accomplished by creating property on the component and referring to that property. If you are able to use the `{{#let}}` helper (useful in template only components), using `{{#let}}` makes the usage clearer.
|
|
304
234
|
|
|
305
235
|
```hbs
|
|
306
|
-
{{#let
|
|
307
|
-
<ol {{sortable-group groupName=myGroupName onChange=
|
|
308
|
-
{{#each model.items as |modelItem|}}
|
|
236
|
+
{{#let 'products' as |myGroupName|}}
|
|
237
|
+
<ol {{sortable-group groupName=myGroupName onChange=this.reorderItems}}>
|
|
238
|
+
{{#each @model.items as |modelItem|}}
|
|
309
239
|
<li {{sortable-item groupName=myGroupName model=modelItem}}>
|
|
310
240
|
{{modelItem.name}}
|
|
311
|
-
<span class=
|
|
241
|
+
<span class='handle' {{sortable-handle}}>↕</span>
|
|
312
242
|
</li>
|
|
313
243
|
{{/each}}
|
|
314
244
|
</ol>
|
|
315
245
|
{{/let}}
|
|
316
246
|
```
|
|
317
247
|
|
|
318
|
-
|
|
319
248
|
### Disabling Drag (Experimental)
|
|
320
|
-
|
|
249
|
+
|
|
250
|
+
`sortable-item` exposes an optional `disabled` (previously `isDraggingDisabled`) flag that you can use to disable reordering for that particular item. Disabling and item won't prevent it from changing position in the array. The user can still move other non-disabled items to over it.
|
|
251
|
+
|
|
321
252
|
This flag is intended as an utility to make your life easier with 3 main benefits:
|
|
253
|
+
|
|
322
254
|
1. You can now specify which `sortable-item` are not intended to be draggable/sortable.
|
|
323
255
|
2. You do not have to duplicate the `sortable-item` UI just for the purpose of disabling the `sorting` behavior.
|
|
324
256
|
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.
|
|
@@ -330,40 +262,35 @@ No data is mutated by `sortable-group` or `sortable-item`. In the spirit of “d
|
|
|
330
262
|
Each item takes a `model` property. This should be fairly self-explanatory but it’s important to note that it doesn’t do anything with this object besides keeping a reference for later use in `onChange`.
|
|
331
263
|
|
|
332
264
|
### Accessibility
|
|
265
|
+
|
|
333
266
|
The `sortable-group` has support for the following accessibility functionality:
|
|
334
267
|
|
|
335
268
|
#### Built-in Functionalities
|
|
336
269
|
|
|
337
|
-
##### Semantic HTML
|
|
338
|
-
|
|
339
|
-
component
|
|
340
|
-
- `sortable-group`
|
|
341
|
-
an ordered list, `ol`, by default.
|
|
342
|
-
- `sortable-item`
|
|
343
|
-
a list item, `li`, by default.
|
|
344
|
-
|
|
345
|
-
The modifier version can be attached to to any element that makes sense,
|
|
346
|
-
|
|
347
270
|
##### Keyboard Navigation
|
|
271
|
+
|
|
348
272
|
There are 4 modes during keyboard navigation:
|
|
273
|
+
|
|
349
274
|
- **ACTIVATE**
|
|
350
275
|
enables the keyboard navigation.
|
|
351
|
-
Activate via
|
|
276
|
+
Activate via `ENTER/SPACE`
|
|
352
277
|
- **MOVE**
|
|
353
278
|
enables item(s) to be moved up, down, left, or right based on `direction`.
|
|
354
|
-
Activate via
|
|
279
|
+
Activate via `ARROW UP/DOWN/LEFT/RIGHT`
|
|
355
280
|
- **CONFIRM**
|
|
356
281
|
submits the new sort order, invokes the `onChange` action.
|
|
357
|
-
Activate via
|
|
282
|
+
Activate via `ENTER/SPACE`.
|
|
358
283
|
- **CANCEL**
|
|
359
284
|
cancels the new sort order, reverts back to the old sort order.
|
|
360
|
-
Activate via
|
|
285
|
+
Activate via `ESCAPE` or when `focus` is lost.
|
|
361
286
|
|
|
362
287
|
##### Focus Management
|
|
288
|
+
|
|
363
289
|
- When `focus` is on a `item` or `handle`, user can effectively select the `item` via `ENTER/SPACE`. This is the `ACTIVATE` mode.
|
|
364
290
|
- While `ACTIVATE`, the `focus` is locked on `sortable-group` container and will not be lost until `CONFIRM`, `CANCEL`, or `focus` is lost.
|
|
365
291
|
|
|
366
292
|
#### User configurable
|
|
293
|
+
|
|
367
294
|
##### Screen Reader
|
|
368
295
|
|
|
369
296
|
The default language for `ember-sortable` is English. Any language can be supported by passing in the configuration below in the appropriate language.
|
|
@@ -372,6 +299,7 @@ The default language for `ember-sortable` is English. Any language can be suppor
|
|
|
372
299
|
a name for the item. Defaults to `item`.
|
|
373
300
|
- **a11yAnnouncementConfig**
|
|
374
301
|
a map of `action enums` to `functions` that takes the following `config`, which is exposed by `sortable-group`.
|
|
302
|
+
|
|
375
303
|
```javascript
|
|
376
304
|
a11yAnnounceConfig = {
|
|
377
305
|
a11yItemName, // name associated with the name
|
|
@@ -379,11 +307,13 @@ a11yAnnounceConfig = {
|
|
|
379
307
|
maxLength, // length of the items
|
|
380
308
|
direction, // x or y
|
|
381
309
|
delta, // +1 means down or right, -1 means up or left
|
|
382
|
-
}
|
|
310
|
+
};
|
|
383
311
|
```
|
|
312
|
+
|
|
384
313
|
and returns a `string` constructed from the `config`.
|
|
385
314
|
|
|
386
315
|
**Default value**
|
|
316
|
+
|
|
387
317
|
```javascript
|
|
388
318
|
{
|
|
389
319
|
ACTIVATE: function({ a11yItemName, index, maxLength, direction }) {
|
|
@@ -411,6 +341,7 @@ and returns a `string` constructed from the `config`.
|
|
|
411
341
|
```
|
|
412
342
|
|
|
413
343
|
##### Visual Indicator
|
|
344
|
+
|
|
414
345
|
- **handleVisualClass**
|
|
415
346
|
This class will be added to the `sortable-handle` during `ACTIVATE` and `MOVE` operations. This allows you to add custom styles such as `visual arrows` via `pseudo` classes.
|
|
416
347
|
|
|
@@ -421,9 +352,9 @@ and returns a `string` constructed from the `config`.
|
|
|
421
352
|
|
|
422
353
|
`ember-sortable` exposes some acceptance test helpers:
|
|
423
354
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
355
|
+
- [`drag`][drag]: Drags elements by an offset specified in pixels.
|
|
356
|
+
- [`reorder`][reorder]: Reorders elements to the specified state.
|
|
357
|
+
- [`keyboard`][keyboard]: Keycode constants for quick.
|
|
427
358
|
|
|
428
359
|
[drag]: addon-test-support/helpers/drag.js
|
|
429
360
|
[reorder]: addon-test-support/helpers/reorder.js
|
|
@@ -432,32 +363,35 @@ and returns a `string` constructed from the `config`.
|
|
|
432
363
|
To include them in your application, you can import them:
|
|
433
364
|
|
|
434
365
|
```js
|
|
435
|
-
import { drag, reorder }
|
|
436
|
-
import {
|
|
366
|
+
import { drag, reorder } from 'ember-sortable/test-support/helpers';
|
|
367
|
+
import {
|
|
368
|
+
ENTER_KEY_CODE,
|
|
369
|
+
SPACE_KEY_CODE,
|
|
370
|
+
ESCAPE_KEY_CODE,
|
|
371
|
+
ARROW_KEY_CODES,
|
|
372
|
+
} from 'ember-sortable/test-support/utils/keyboard';
|
|
437
373
|
```
|
|
438
374
|
|
|
439
375
|
### Examples
|
|
376
|
+
|
|
440
377
|
`Reorder`
|
|
378
|
+
|
|
441
379
|
```js
|
|
442
|
-
await reorder(
|
|
443
|
-
'mouse',
|
|
444
|
-
'[data-test-vertical-demo-handle]',
|
|
445
|
-
...order
|
|
446
|
-
);
|
|
380
|
+
await reorder('mouse', '[data-test-vertical-demo-handle]', ...order);
|
|
447
381
|
```
|
|
448
382
|
|
|
449
383
|
`Drag`
|
|
384
|
+
|
|
450
385
|
```js
|
|
451
|
-
await drag('mouse', '[data-test-scrollable-demo-handle] .handle', () => {
|
|
386
|
+
await drag('mouse', '[data-test-scrollable-demo-handle] .handle', () => {
|
|
387
|
+
return { dy: itemHeight() * 2 + 1, dx: undefined };
|
|
388
|
+
});
|
|
452
389
|
```
|
|
453
390
|
|
|
454
391
|
`Keyboard`
|
|
392
|
+
|
|
455
393
|
```js
|
|
456
|
-
await triggerKeyEvent(
|
|
457
|
-
'[data-test-vertical-demo-handle]',
|
|
458
|
-
'keydown',
|
|
459
|
-
ENTER_KEY_CODE
|
|
460
|
-
);
|
|
394
|
+
await triggerKeyEvent('[data-test-vertical-demo-handle]', 'keydown', ENTER_KEY_CODE);
|
|
461
395
|
```
|
|
462
396
|
|
|
463
397
|
## Developing
|