@@ -93,7 +93,7 @@ class Selection<T> {
93
93
*/
94
94
set value ( value : T ) {
95
95
if ( value === null ) {
96
- this . index = - 1 ;
96
+ this . index = null ;
97
97
} else {
98
98
this . index = ArrayExt . firstIndexOf ( this . _array , value ) ;
99
99
}
@@ -103,9 +103,9 @@ class Selection<T> {
103
103
* Get the index of the currently selected item.
104
104
*
105
105
* #### Notes
106
- * This will be `-1 ` if no item is selected.
106
+ * This will be `null ` if no item is selected.
107
107
*/
108
- get index ( ) : number {
108
+ get index ( ) : number | null {
109
109
return this . _index ;
110
110
}
111
111
@@ -115,14 +115,20 @@ class Selection<T> {
115
115
* @param index - The index to select.
116
116
*
117
117
* #### Notes
118
- * If the value is out of range, the index will be set to `-1 `, which
118
+ * If the value is out of range, the index will be set to `null `, which
119
119
* indicates no item is selected.
120
120
*/
121
- set index ( index : number ) {
121
+ set index ( index : number | null ) {
122
122
// Coerce the value to an index.
123
- let i = Math . floor ( index ) ;
124
- if ( i < 0 || i >= this . _array . length ) {
125
- i = - 1 ;
123
+ let i ;
124
+ if ( index !== null ) {
125
+ i = Math . floor ( index ) ;
126
+ if ( i < 0 || i >= this . _array . length ) {
127
+ i = null ;
128
+ }
129
+ }
130
+ else {
131
+ i = null ;
126
132
}
127
133
128
134
// Bail early if the index will not change.
@@ -194,7 +200,7 @@ class Selection<T> {
194
200
195
201
// Handle the behavior where the new item is always selected,
196
202
// or the behavior where the new item is selected if needed.
197
- if ( bh === 'select-item' || ( bh === 'select-item-if-needed' && ci === - 1 ) ) {
203
+ if ( bh === 'select-item' || ( bh === 'select-item-if-needed' && ci === null ) ) {
198
204
this . _index = i ;
199
205
this . _value = item ;
200
206
this . _previousValue = cv ;
@@ -240,19 +246,19 @@ class Selection<T> {
240
246
let pv = this . _value ;
241
247
242
248
// Reset the current index and previous item.
243
- this . _index = - 1 ;
249
+ this . _index = null ;
244
250
this . _value = null ;
245
251
this . _previousValue = null ;
246
252
247
253
// If no item was selected, there's nothing else to do.
248
- if ( pi === - 1 ) {
254
+ if ( pi === null ) {
249
255
return ;
250
256
}
251
257
252
258
// Emit the current changed signal.
253
259
this . _selectionChanged . emit ( {
254
260
previousIndex : pi , previousValue : pv ,
255
- currentIndex : - 1 , currentValue : null
261
+ currentIndex : this . _index , currentValue : this . _value
256
262
} ) ;
257
263
}
258
264
@@ -283,12 +289,12 @@ class Selection<T> {
283
289
// No item gets selected if the vector is empty.
284
290
if ( this . _array . length === 0 ) {
285
291
// Reset the current index and previous item.
286
- this . _index = - 1 ;
292
+ this . _index = null ;
287
293
this . _value = null ;
288
294
this . _previousValue = null ;
289
295
this . _selectionChanged . emit ( {
290
296
previousIndex : i , previousValue : item ,
291
- currentIndex : - 1 , currentValue : null
297
+ currentIndex : this . _index , currentValue : this . _value
292
298
} ) ;
293
299
return ;
294
300
}
@@ -334,12 +340,12 @@ class Selection<T> {
334
340
}
335
341
336
342
// Otherwise, no item gets selected.
337
- this . _index = - 1 ;
343
+ this . _index = null ;
338
344
this . _value = null ;
339
345
this . _previousValue = null ;
340
346
this . _selectionChanged . emit ( {
341
347
previousIndex : i , previousValue : item ,
342
- currentIndex : - 1 , currentValue : null
348
+ currentIndex : this . _index , currentValue : this . _value
343
349
} ) ;
344
350
}
345
351
@@ -348,7 +354,7 @@ class Selection<T> {
348
354
*/
349
355
private _updateSelectedValue ( ) {
350
356
let i = this . _index ;
351
- this . _value = i !== - 1 ? this . _array [ i ] : null ;
357
+ this . _value = i !== null ? this . _array [ i ] : null ;
352
358
}
353
359
354
360
private _array : ReadonlyArray < T > = null ;
0 commit comments