File tree Expand file tree Collapse file tree 3 files changed +36
-9
lines changed Expand file tree Collapse file tree 3 files changed +36
-9
lines changed Original file line number Diff line number Diff line change 34
34
WALL-E
35
35
</ label >
36
36
</ li >
37
+ < li class ="task-list-item ">
38
+ < label >
39
+ < input type ="checkbox " class ="task-list-item-checkbox ">
40
+ R2-D2
41
+ </ label >
42
+
43
+ < ul class ="contains-task-list ">
44
+ < li class ="task-list-item ">
45
+ < label >
46
+ < input type ="checkbox " class ="task-list-item-checkbox ">
47
+ Baymax
48
+ </ label >
49
+ </ li >
50
+ </ ul >
51
+ </ li >
37
52
< li class ="task-list-item ">
38
53
< label >
39
54
< input type ="checkbox " class ="task-list-item-checkbox ">
Original file line number Diff line number Diff line change @@ -136,12 +136,10 @@ function onListItemMouseOut(event: MouseEvent) {
136
136
}
137
137
138
138
// Returns the list item position as a (list index, item index) tuple.
139
- // Listen on top-level task lists because item indexing includes nested task lists.
140
- function position ( el : Element ) : [ number , number ] {
141
- const list = rootTaskList ( el )
139
+ function position ( checkbox : HTMLInputElement ) : [ number , number ] {
140
+ const list = taskList ( checkbox )
142
141
if ( ! list ) throw new Error ( '.contains-task-list not found' )
143
- const flattened = Array . from ( list . querySelectorAll ( 'li' ) )
144
- const index = flattened . indexOf ( el . closest ( '.task-list-item' ) )
142
+ const index = Array . from ( list . children ) . indexOf ( checkbox . closest ( '.task-list-item' ) )
145
143
return [ listIndex ( list ) , index ]
146
144
}
147
145
Original file line number Diff line number Diff line change @@ -34,15 +34,29 @@ describe('task-lists element', function() {
34
34
<input id="wall-e" type="checkbox" class="task-list-item-checkbox"> WALL-E
35
35
</li>
36
36
</ul>
37
- <ul>
37
+
38
+ <ol>
38
39
<li>
40
+ Nested
39
41
<ul class="contains-task-list">
40
42
<li class="task-list-item">
41
- <input id="baymax" type="checkbox" class="task-list-item-checkbox"> Baymax
43
+ <label>
44
+ <input type="checkbox" class="task-list-item-checkbox">
45
+ R2-D2
46
+ </label>
47
+
48
+ <ul class="contains-task-list">
49
+ <li class="task-list-item">
50
+ <label>
51
+ <input id="baymax" type="checkbox" class="task-list-item-checkbox">
52
+ Baymax
53
+ </label>
54
+ </li>
55
+ </ul>
42
56
</li>
43
57
</ul>
44
58
</li>
45
- </ul >
59
+ </ol >
46
60
</task-lists>`
47
61
document . body . append ( container )
48
62
} )
@@ -76,7 +90,7 @@ describe('task-lists element', function() {
76
90
list . addEventListener ( 'task-lists:check' , function ( event ) {
77
91
called = true
78
92
const { position, checked} = event . detail
79
- assert . deepEqual ( position , [ 3 , 0 ] )
93
+ assert . deepEqual ( position , [ 4 , 0 ] )
80
94
assert ( checked )
81
95
} )
82
96
You can’t perform that action at this time.
0 commit comments