@@ -35,6 +35,15 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
35
35
@property ( { type : Boolean , reflect : true } )
36
36
disabled = false ;
37
37
38
+ /**
39
+ * Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
40
+ * @type {boolean }
41
+ * @attr
42
+ * @default false
43
+ */
44
+ @property ( { type : Boolean , reflect : true } )
45
+ readonly = false ;
46
+
38
47
get value ( ) {
39
48
return super . value ;
40
49
}
@@ -121,6 +130,10 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
121
130
this . _radioElements ?. forEach ( el => ( el . disabled = value ) ) ;
122
131
}
123
132
133
+ private _setReadonlyOnRadios ( value : boolean ) {
134
+ this . _radioElements ?. forEach ( el => ( el . readonly = value ) ) ;
135
+ }
136
+
124
137
private _handleSlotChange ( e : Event ) {
125
138
e . stopPropagation ( ) ;
126
139
// TODO: make sure to diff new and old ones to only add and remove event listeners on relevant elements.
@@ -152,10 +165,15 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
152
165
} ) ;
153
166
154
167
this . _setNameOnRadios ( this . name ) ;
168
+
155
169
if ( this . disabled ) {
156
170
this . _setDisableOnRadios ( true ) ;
157
171
}
158
172
173
+ if ( this . readonly ) {
174
+ this . _setReadonlyOnRadios ( true ) ;
175
+ }
176
+
159
177
const checkedRadios = this . _radioElements . filter ( el => el . checked === true ) ;
160
178
161
179
if ( checkedRadios . length > 1 ) {
@@ -172,13 +190,18 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
172
190
}
173
191
174
192
if ( checkedRadios . length === 1 ) {
175
- this . value = checkedRadios [ 0 ] . value ;
176
- this . _selected = this . _radioElements . indexOf ( checkedRadios [ 0 ] ) ;
177
- if ( checkedRadios [ 0 ] . disabled === false ) {
193
+ const firstCheckedRadio = checkedRadios [ 0 ] ;
194
+ this . value = firstCheckedRadio . value ;
195
+ this . _selected = this . _radioElements . indexOf ( firstCheckedRadio ) ;
196
+
197
+ if (
198
+ firstCheckedRadio . disabled === false &&
199
+ firstCheckedRadio . readonly === false
200
+ ) {
178
201
this . _radioElements . forEach ( el => {
179
202
el . makeUnfocusable ( ) ;
180
203
} ) ;
181
- checkedRadios [ 0 ] . makeFocusable ( ) ;
204
+ firstCheckedRadio . makeFocusable ( ) ;
182
205
} else {
183
206
this . _makeFirstEnabledFocusable ( ) ;
184
207
}
@@ -206,12 +229,16 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
206
229
let i = this . _selected === null ? 0 : 1 ; //If we have something selected we will skip checking it self.
207
230
while ( i < len ) {
208
231
let checkIndex = ( origin + i * direction ) % len ;
232
+ const radioElement = this . _radioElements [ checkIndex ] ;
233
+
209
234
if ( checkIndex < 0 ) {
210
235
checkIndex += len ;
211
236
}
212
- if ( this . _radioElements [ checkIndex ] . disabled === false ) {
213
- return this . _radioElements [ checkIndex ] ;
237
+
238
+ if ( radioElement . disabled === false && radioElement . readonly === false ) {
239
+ return radioElement ;
214
240
}
241
+
215
242
i ++ ;
216
243
}
217
244
return null ;
@@ -281,6 +308,10 @@ export class UUIRadioGroupElement extends UUIFormControlMixin(LitElement, '') {
281
308
this . _setDisableOnRadios ( this . disabled ) ;
282
309
}
283
310
311
+ if ( _changedProperties . has ( 'readonly' ) ) {
312
+ this . _setReadonlyOnRadios ( this . readonly ) ;
313
+ }
314
+
284
315
if ( _changedProperties . has ( 'name' ) ) {
285
316
this . _setNameOnRadios ( _changedProperties . get ( 'name' ) as string ) ;
286
317
}
0 commit comments