@@ -273,11 +273,6 @@ abstract class BaseCheckbox extends Widget {
273
273
super ( ) ;
274
274
275
275
this . applyStyles ( ) ;
276
-
277
- this . _register ( this . checkbox . onChange ( keyboard => {
278
- this . applyStyles ( ) ;
279
- this . _onChange . fire ( keyboard ) ;
280
- } ) ) ;
281
276
}
282
277
283
278
get enabled ( ) : boolean {
@@ -322,12 +317,9 @@ abstract class BaseCheckbox extends Widget {
322
317
export class Checkbox extends BaseCheckbox {
323
318
constructor ( title : string , isChecked : boolean , styles : ICheckboxStyles ) {
324
319
const toggle = new Toggle ( { title, isChecked, icon : Codicon . check , actionClassName : BaseCheckbox . CLASS_NAME , hoverDelegate : styles . hoverDelegate , ...unthemedToggleStyles } ) ;
325
-
326
320
super ( toggle , toggle . domNode , styles ) ;
327
- this . _register ( toggle ) ;
328
-
329
- this . applyStyles ( ) ;
330
321
322
+ this . _register ( toggle ) ;
331
323
this . _register ( this . checkbox . onChange ( keyboard => {
332
324
this . applyStyles ( ) ;
333
325
this . _onChange . fire ( keyboard ) ;
@@ -340,19 +332,27 @@ export class Checkbox extends BaseCheckbox {
340
332
341
333
set checked ( newIsChecked : boolean ) {
342
334
this . checkbox . checked = newIsChecked ;
343
- if ( newIsChecked ) {
335
+ this . applyStyles ( ) ;
336
+ }
337
+
338
+ protected override applyStyles ( enabled ?: boolean ) : void {
339
+ if ( this . checkbox . checked ) {
344
340
this . checkbox . setIcon ( Codicon . check ) ;
345
341
} else {
346
342
this . checkbox . setIcon ( undefined ) ;
347
343
}
348
- this . applyStyles ( ) ;
344
+ super . applyStyles ( enabled ) ;
349
345
}
350
346
}
351
347
352
348
export class TriStateCheckbox extends BaseCheckbox {
353
- constructor ( title : string , initialState : boolean | 'partial' , styles : ICheckboxStyles ) {
349
+ constructor (
350
+ title : string ,
351
+ private _state : boolean | 'partial' ,
352
+ styles : ICheckboxStyles
353
+ ) {
354
354
let icon : ThemeIcon | undefined ;
355
- switch ( initialState ) {
355
+ switch ( _state ) {
356
356
case true :
357
357
icon = Codicon . check ;
358
358
break ;
@@ -365,30 +365,40 @@ export class TriStateCheckbox extends BaseCheckbox {
365
365
}
366
366
const checkbox = new Toggle ( {
367
367
title,
368
- isChecked : initialState === true ,
368
+ isChecked : _state === true ,
369
369
icon,
370
370
actionClassName : Checkbox . CLASS_NAME ,
371
371
hoverDelegate : styles . hoverDelegate ,
372
372
...unthemedToggleStyles
373
373
} ) ;
374
-
375
374
super (
376
375
checkbox ,
377
376
checkbox . domNode ,
378
377
styles
379
378
) ;
379
+
380
380
this . _register ( checkbox ) ;
381
+ this . _register ( this . checkbox . onChange ( keyboard => {
382
+ this . _state = this . checkbox . checked ;
383
+ this . applyStyles ( ) ;
384
+ this . _onChange . fire ( keyboard ) ;
385
+ } ) ) ;
381
386
}
382
387
383
388
get checked ( ) : boolean | 'partial' {
384
- return this . checkbox . checked ;
389
+ return this . _state ;
385
390
}
386
391
387
392
set checked ( newState : boolean | 'partial' ) {
388
- const checked = newState === true ;
389
- this . checkbox . checked = checked ;
393
+ if ( this . _state !== newState ) {
394
+ this . _state = newState ;
395
+ this . checkbox . checked = newState === true ;
396
+ this . applyStyles ( ) ;
397
+ }
398
+ }
390
399
391
- switch ( newState ) {
400
+ protected override applyStyles ( enabled ?: boolean ) : void {
401
+ switch ( this . _state ) {
392
402
case true :
393
403
this . checkbox . setIcon ( Codicon . check ) ;
394
404
break ;
@@ -399,8 +409,7 @@ export class TriStateCheckbox extends BaseCheckbox {
399
409
this . checkbox . setIcon ( undefined ) ;
400
410
break ;
401
411
}
402
-
403
- this . applyStyles ( ) ;
412
+ super . applyStyles ( enabled ) ;
404
413
}
405
414
}
406
415
0 commit comments