@@ -159,12 +159,12 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
159159 @Input ( )
160160 get selected ( ) : boolean { return this . _selected ; }
161161 set selected ( value : boolean ) {
162- this . _selected = coerceBooleanProperty ( value ) ;
163- this . selectionChange . emit ( {
164- source : this ,
165- isUserInput : false ,
166- selected : value
167- } ) ;
162+ const coercedValue = coerceBooleanProperty ( value ) ;
163+
164+ if ( coercedValue !== this . _selected ) {
165+ this . _selected = coercedValue ;
166+ this . _dispatchSelectionChange ( ) ;
167+ }
168168 }
169169 protected _selected : boolean = false ;
170170
@@ -262,45 +262,32 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
262262
263263 /** Selects the chip. */
264264 select ( ) : void {
265- this . _selected = true ;
266- this . selectionChange . emit ( {
267- source : this ,
268- isUserInput : false ,
269- selected : true
270- } ) ;
265+ if ( ! this . _selected ) {
266+ this . _selected = true ;
267+ this . _dispatchSelectionChange ( ) ;
268+ }
271269 }
272270
273271 /** Deselects the chip. */
274272 deselect ( ) : void {
275- this . _selected = false ;
276- this . selectionChange . emit ( {
277- source : this ,
278- isUserInput : false ,
279- selected : false
280- } ) ;
273+ if ( this . _selected ) {
274+ this . _selected = false ;
275+ this . _dispatchSelectionChange ( ) ;
276+ }
281277 }
282278
283279 /** Select this chip and emit selected event */
284280 selectViaInteraction ( ) : void {
285- this . _selected = true ;
286- // Emit select event when selected changes.
287- this . selectionChange . emit ( {
288- source : this ,
289- isUserInput : true ,
290- selected : true
291- } ) ;
281+ if ( ! this . _selected ) {
282+ this . _selected = true ;
283+ this . _dispatchSelectionChange ( true ) ;
284+ }
292285 }
293286
294287 /** Toggles the current selected state of this chip. */
295288 toggleSelected ( isUserInput : boolean = false ) : boolean {
296289 this . _selected = ! this . selected ;
297-
298- this . selectionChange . emit ( {
299- source : this ,
300- isUserInput,
301- selected : this . _selected
302- } ) ;
303-
290+ this . _dispatchSelectionChange ( isUserInput ) ;
304291 return this . selected ;
305292 }
306293
@@ -375,6 +362,14 @@ export class MatChip extends _MatChipMixinBase implements FocusableOption, OnDes
375362 } ) ;
376363 } ) ;
377364 }
365+
366+ private _dispatchSelectionChange ( isUserInput = false ) {
367+ this . selectionChange . emit ( {
368+ source : this ,
369+ isUserInput,
370+ selected : this . _selected
371+ } ) ;
372+ }
378373}
379374
380375
0 commit comments