File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
projects/angular/components/ui-suggest/src Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 92
92
(keydown.tab) ="close(false) "
93
93
(keydown.shift.tab) ="close() ">
94
94
< mat-chip *ngFor ="let option of value; let i = index "
95
- (removed) ="deselectItem(option) ">
95
+ (removed) ="deselectItem(option) "
96
+ [removable] ="!readonly ">
96
97
< span >
97
98
{{ intl.translateLabel(option.text) }}
98
99
</ span >
106
107
[uiAutofocus] ="isOpen "
107
108
[refocus] ="isOpen "
108
109
[placeholder] ="(isFormControl && !empty) ? '' : defaultValue "
110
+ [readonly] ="readonly "
109
111
[formControl] ="inputControl "
110
112
[matChipInputFor] ="chipList "
111
113
[attr.maxlength] ="maxLength "
Original file line number Diff line number Diff line change @@ -1252,6 +1252,32 @@ const sharedSpecifications = (
1252
1252
1253
1253
discardPeriodicTasks ( ) ;
1254
1254
} ) ) ;
1255
+
1256
+ it ( 'should NOT be able to remove chip if readonly' , fakeAsync ( ( ) => {
1257
+ const items = component . items ! . slice ( 0 , 3 ) ;
1258
+ component . value = items ;
1259
+ component . readonly = true ;
1260
+ fixture . detectChanges ( ) ;
1261
+ tick ( ) ;
1262
+
1263
+ const initialChips = fixture . debugElement . queryAll ( By . css ( '.mat-chip' ) ) ;
1264
+ expect ( initialChips . length ) . toBe ( 3 ) ;
1265
+
1266
+ const chipRemoveButton = getNativeElement < HTMLButtonElement > ( initialChips [ 1 ] . query ( By . css ( 'button' ) ) ) ;
1267
+ chipRemoveButton . click ( ) ;
1268
+
1269
+ fixture . detectChanges ( ) ;
1270
+ tick ( 5000 ) ;
1271
+
1272
+ const updatedChips = fixture . debugElement
1273
+ . queryAll ( By . css ( '.mat-chip span' ) )
1274
+ . map ( el => getNativeElement < HTMLSpanElement > ( el ) ) ;
1275
+
1276
+ expect ( updatedChips . length ) . toEqual ( 3 ) ;
1277
+ expect ( updatedChips . map ( chip => chip . innerText ) ) . toEqual ( items . map ( item => item . text ) ) ;
1278
+
1279
+ discardPeriodicTasks ( ) ;
1280
+ } ) ) ;
1255
1281
} ) ;
1256
1282
} ) ;
1257
1283
You can’t perform that action at this time.
0 commit comments