@@ -24,6 +24,7 @@ import {
24
24
QueryList ,
25
25
ViewChild ,
26
26
booleanAttribute ,
27
+ signal ,
27
28
} from '@angular/core' ;
28
29
import { Subject } from 'rxjs' ;
29
30
import { MAT_OPTGROUP , MatOptgroup } from './optgroup' ;
@@ -83,9 +84,9 @@ export class MatOptionSelectionChange<T = any> {
83
84
imports : [ MatPseudoCheckbox , MatRipple ] ,
84
85
} )
85
86
export class MatOption < T = any > implements FocusableOption , AfterViewChecked , OnDestroy {
86
- private _selected = false ;
87
- private _active = false ;
88
- private _disabled = false ;
87
+ private _selected = signal ( false ) ;
88
+ private _active = signal ( false ) ;
89
+ private _disabled = signal ( false ) ;
89
90
private _mostRecentViewValue = '' ;
90
91
91
92
/** Whether the wrapping component is in multiple selection mode. */
@@ -95,7 +96,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
95
96
96
97
/** Whether or not the option is currently selected. */
97
98
get selected ( ) : boolean {
98
- return this . _selected ;
99
+ return this . _selected ( ) ;
99
100
}
100
101
101
102
/** The form value of the option. */
@@ -107,10 +108,10 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
107
108
/** Whether the option is disabled. */
108
109
@Input ( { transform : booleanAttribute } )
109
110
get disabled ( ) : boolean {
110
- return ( this . group && this . group . disabled ) || this . _disabled ;
111
+ return ( this . group && this . group . disabled ) || this . _disabled ( ) ;
111
112
}
112
113
set disabled ( value : boolean ) {
113
- this . _disabled = value ;
114
+ this . _disabled . set ( value ) ;
114
115
}
115
116
116
117
/** Whether ripples for the option are disabled. */
@@ -147,7 +148,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
147
148
* for components like autocomplete where focus must remain on the input.
148
149
*/
149
150
get active ( ) : boolean {
150
- return this . _active ;
151
+ return this . _active ( ) ;
151
152
}
152
153
153
154
/**
@@ -161,9 +162,8 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
161
162
162
163
/** Selects the option. */
163
164
select ( emitEvent = true ) : void {
164
- if ( ! this . _selected ) {
165
- this . _selected = true ;
166
- this . _changeDetectorRef . markForCheck ( ) ;
165
+ if ( ! this . _selected ( ) ) {
166
+ this . _selected . set ( true ) ;
167
167
168
168
if ( emitEvent ) {
169
169
this . _emitSelectionChangeEvent ( ) ;
@@ -173,9 +173,8 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
173
173
174
174
/** Deselects the option. */
175
175
deselect ( emitEvent = true ) : void {
176
- if ( this . _selected ) {
177
- this . _selected = false ;
178
- this . _changeDetectorRef . markForCheck ( ) ;
176
+ if ( this . _selected ( ) ) {
177
+ this . _selected . set ( false ) ;
179
178
180
179
if ( emitEvent ) {
181
180
this . _emitSelectionChangeEvent ( ) ;
@@ -200,9 +199,8 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
200
199
* events will display the proper options as active on arrow key events.
201
200
*/
202
201
setActiveStyles ( ) : void {
203
- if ( ! this . _active ) {
204
- this . _active = true ;
205
- this . _changeDetectorRef . markForCheck ( ) ;
202
+ if ( ! this . _active ( ) ) {
203
+ this . _active . set ( true ) ;
206
204
}
207
205
}
208
206
@@ -213,8 +211,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
213
211
*/
214
212
setInactiveStyles ( ) : void {
215
213
if ( this . _active ) {
216
- this . _active = false ;
217
- this . _changeDetectorRef . markForCheck ( ) ;
214
+ this . _active . set ( false ) ;
218
215
}
219
216
}
220
217
@@ -239,8 +236,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
239
236
*/
240
237
_selectViaInteraction ( ) : void {
241
238
if ( ! this . disabled ) {
242
- this . _selected = this . multiple ? ! this . _selected : true ;
243
- this . _changeDetectorRef . markForCheck ( ) ;
239
+ this . _selected . set ( this . multiple ? ! this . _selected ( ) : true ) ;
244
240
this . _emitSelectionChangeEvent ( true ) ;
245
241
}
246
242
}
@@ -264,7 +260,7 @@ export class MatOption<T = any> implements FocusableOption, AfterViewChecked, On
264
260
// we have to check for changes in the DOM ourselves and dispatch an event. These checks are
265
261
// relatively cheap, however we still limit them only to selected options in order to avoid
266
262
// hitting the DOM too often.
267
- if ( this . _selected ) {
263
+ if ( this . _selected ( ) ) {
268
264
const viewValue = this . viewValue ;
269
265
270
266
if ( viewValue !== this . _mostRecentViewValue ) {
0 commit comments