@@ -88,6 +88,13 @@ class TableSelection extends UI5Element implements ITableFeature {
88
88
_rowsLength = 0 ;
89
89
_rangeSelection ?: { selected : boolean , isUp : boolean | null , rows : TableRow [ ] , isMouse : boolean , shiftPressed : boolean } | null ;
90
90
91
+ onClickCaptureBound : ( e : MouseEvent ) => void ;
92
+
93
+ constructor ( ) {
94
+ super ( ) ;
95
+ this . onClickCaptureBound = this . _onClickCapture . bind ( this ) ;
96
+ }
97
+
91
98
onTableActivate ( table : Table ) {
92
99
this . _table = table ;
93
100
this . _invalidateTableAndRows ( ) ;
@@ -108,6 +115,12 @@ class TableSelection extends UI5Element implements ITableFeature {
108
115
this . _rowsLength = this . _table . rows . length ;
109
116
this . _table . headerRow [ 0 ] . _invalidate ++ ;
110
117
}
118
+
119
+ this . _table ?. removeEventListener ( "click" , this . onClickCaptureBound ) ;
120
+ }
121
+
122
+ onTableAfterRendering ( ) : void {
123
+ this . _table ?. addEventListener ( "click" , this . onClickCaptureBound , { capture : true } ) ;
111
124
}
112
125
113
126
isSelectable ( ) : boolean {
@@ -272,7 +285,7 @@ class TableSelection extends UI5Element implements ITableFeature {
272
285
}
273
286
}
274
287
275
- _onclick ( e : MouseEvent ) {
288
+ _onClickCapture ( e : MouseEvent ) {
276
289
if ( ! this . _table || this . mode !== TableSelectionMode . Multiple ) {
277
290
return ;
278
291
}
@@ -294,11 +307,13 @@ class TableSelection extends UI5Element implements ITableFeature {
294
307
const startIndex = this . _table . rows . indexOf ( startRow ) ;
295
308
const endIndex = this . _table . rows . indexOf ( row ) ;
296
309
310
+ const selectionState = this . isSelected ( startRow ) ;
311
+
297
312
// When doing a range selection and clicking on an already selected row, the checked status should not change
298
313
// Therefore, we need to manually set the checked attribute again, as clicking it would deselect it and leads to
299
314
// a visual inconsistency.
300
- row . shadowRoot ?. querySelector ( "#selection-component" ) ?. toggleAttribute ( "checked" , true ) ;
301
- e . stopImmediatePropagation ( ) ;
315
+ row . shadowRoot ?. querySelector ( "#selection-component" ) ?. toggleAttribute ( "checked" , selectionState ) ;
316
+ e . stopPropagation ( ) ;
302
317
303
318
if ( startIndex === - 1 || endIndex === - 1 || row . rowKey === startRow . rowKey || row . rowKey === this . _rangeSelection . rows [ this . _rangeSelection . rows . length - 1 ] . rowKey ) {
304
319
return ;
0 commit comments