@@ -18,12 +18,17 @@ export default class extends Controller {
18
18
connect ( ) {
19
19
events ( this )
20
20
this . buttonTarget . disabled = true
21
+
22
+ if ( ! isNaN ( this . selectedIdValue ) ) {
23
+ const currentSelection = this . selectById ( this . selectedIdValue )
24
+ this . reassignCheckmark ( currentSelection )
25
+ }
21
26
}
22
27
23
28
selectFolder ( event ) {
24
29
const currentSelection = event . currentTarget
25
30
const id = currentSelection . dataset . id
26
- const previousSelection = this . previouslySelected ( )
31
+ const previousSelection = this . selectById ( this . selectedIdValue )
27
32
28
33
if ( currentSelection === previousSelection ) { return }
29
34
@@ -33,21 +38,25 @@ export default class extends Controller {
33
38
this . toggleButton ( )
34
39
}
35
40
36
- previouslySelected ( ) {
41
+ selectById ( id ) {
37
42
return this . itemTargets . find ( item => {
38
- return Number ( item . dataset . id ) === this . selectedIdValue
43
+ return Number ( item . dataset . id ) === id
39
44
} )
40
45
}
41
46
42
47
reassignClasses ( previousSelection , currentSelection ) {
43
- previousSelection . classList . remove ( 'move-snippet--item-selected' )
44
- previousSelection . classList . add ( 'move-snippet--item' )
48
+ if ( previousSelection ) {
49
+ previousSelection . classList . remove ( 'move-snippet--item-selected' )
50
+ previousSelection . classList . add ( 'move-snippet--item' )
51
+ }
52
+
45
53
currentSelection . classList . remove ( 'move-snippet--item' )
46
54
currentSelection . classList . add ( 'move-snippet--item-selected' )
47
55
}
48
56
49
57
reassignCheckmark ( currentSelection ) {
50
58
const checkmark = this . checkmarkTarget
59
+ checkmark . classList . remove ( 'hidden' )
51
60
const checkmarkClone = checkmark . cloneNode ( true )
52
61
53
62
checkmark . remove ( )
0 commit comments