@@ -1028,16 +1028,25 @@ export class TabBar<T> extends Widget {
1028
1028
// Add the document mouse up listener.
1029
1029
this . document . addEventListener ( 'pointerup' , this , true ) ;
1030
1030
1031
+ if ( scrollBeforeButtonClicked || scrollAfterButtonClicked ) {
1032
+ this . beginScrolling ( scrollBeforeButtonClicked ? '-' : '+' ) ;
1033
+ return ;
1034
+ }
1035
+
1036
+ this . _clickedTabIndex = index ;
1037
+
1031
1038
// Do nothing else if the middle button or add button is clicked.
1032
1039
if ( event . button === 1 || addButtonClicked ) {
1033
1040
return ;
1034
1041
}
1035
- if ( scrollBeforeButtonClicked || scrollAfterButtonClicked ) {
1036
- this . beginScrolling ( scrollBeforeButtonClicked ? '-' : '+' ) ;
1042
+
1043
+ // Do nothing else if the close icon is clicked.
1044
+ let icon = tabs [ index ] . querySelector ( this . renderer . closeIconSelector ) ;
1045
+ if ( icon && icon . contains ( event . target as HTMLElement ) ) {
1037
1046
return ;
1038
1047
}
1039
1048
1040
- // Initialize the non-measured parts of the drag data.
1049
+ // Initialize the non-measured parts of the drag data,
1041
1050
this . _dragData = {
1042
1051
tab : tabs [ index ] as HTMLElement ,
1043
1052
index : index ,
@@ -1207,14 +1216,7 @@ export class TabBar<T> extends Widget {
1207
1216
return ;
1208
1217
}
1209
1218
1210
- // Do nothing if no drag is in progress.
1211
1219
const data = this . _dragData ;
1212
- if ( ! data ) {
1213
- if ( this . _scrollData ) {
1214
- this . stopScrolling ( ) ;
1215
- }
1216
- return ;
1217
- }
1218
1220
1219
1221
// Stop the event propagation.
1220
1222
event . preventDefault ( ) ;
@@ -1223,17 +1225,22 @@ export class TabBar<T> extends Widget {
1223
1225
// Remove the extra mouse event listeners.
1224
1226
this . document . removeEventListener ( 'pointermove' , this , true ) ;
1225
1227
this . document . removeEventListener ( 'pointerup' , this , true ) ;
1226
- this . document . removeEventListener ( 'keydown' , this , true ) ;
1227
- this . document . removeEventListener ( 'contextmenu' , this , true ) ;
1228
1228
1229
- // Handle a release when the drag is not active.
1230
- if ( ! data . dragActive ) {
1229
+ // Remove extra mouse event listeners which are only added when drag is in progress.
1230
+ if ( data ) {
1231
+ this . document . removeEventListener ( 'pointermove' , this , true ) ;
1232
+ this . document . removeEventListener ( 'keydown' , this , true ) ;
1233
+ this . document . removeEventListener ( 'contextmenu' , this , true ) ;
1234
+ }
1235
+
1236
+ // Handle a release when the drag is not active or not in progress.
1237
+ if ( ! data || ! data . dragActive ) {
1231
1238
// Clear the drag data.
1232
1239
this . _dragData = null ;
1233
1240
1241
+ // Handle mouse release if scrolling was in progress.
1234
1242
if ( this . _scrollData ) {
1235
1243
this . stopScrolling ( ) ;
1236
- return ;
1237
1244
}
1238
1245
// Handle clicking the add button.
1239
1246
let addButtonClicked =
@@ -1253,12 +1260,12 @@ export class TabBar<T> extends Widget {
1253
1260
} ) ;
1254
1261
1255
1262
// Do nothing if the release is not on the original pressed tab.
1256
- if ( index !== data . index ) {
1263
+ if ( index !== this . _clickedTabIndex ) {
1257
1264
return ;
1258
1265
}
1259
1266
1260
1267
// Do nothing if neither press nor release was on a tab.
1261
- if ( index === - 1 && data . index === - 1 ) {
1268
+ if ( index === - 1 && this . _clickedTabIndex === - 1 ) {
1262
1269
return ;
1263
1270
}
1264
1271
@@ -1524,6 +1531,7 @@ export class TabBar<T> extends Widget {
1524
1531
}
1525
1532
1526
1533
private _name : string ;
1534
+ private _clickedTabIndex : number = - 1 ;
1527
1535
private _currentIndex = - 1 ;
1528
1536
private _titles : Title < T > [ ] = [ ] ;
1529
1537
private _orientation : TabBar . Orientation ;
0 commit comments