@@ -262,13 +262,18 @@ export class Checkbox implements ComponentInterface {
262
262
263
263
renderHiddenInput ( true , el , name , checked ? value : '' , disabled ) ;
264
264
265
+ // Determine appropriate accessible name
266
+ const hasLabelContent = el . textContent !== '' ;
267
+ const hasLabelId = inputId + '-lbl' ;
268
+
265
269
return (
266
270
< Host
267
271
role = "checkbox"
268
272
aria-checked = { indeterminate ? 'mixed' : `${ checked } ` }
269
273
aria-describedby = { this . getHintTextID ( ) }
270
274
aria-invalid = { this . getHintTextID ( ) === this . errorTextId }
271
- aria-labelledby = { inputId + '-lbl' }
275
+ aria-labelledby = { hasLabelContent ? hasLabelId : null }
276
+ aria-label = { ! hasLabelContent ? ( inheritedAttributes [ 'aria-label' ] || 'checkbox' ) : null }
272
277
aria-disabled = { disabled ? 'true' : null }
273
278
tabindex = "0"
274
279
onKeyDown = { this . onKeyDown }
@@ -287,13 +292,12 @@ export class Checkbox implements ComponentInterface {
287
292
>
288
293
< label class = "checkbox-wrapper" htmlFor = { inputId } >
289
294
{ /*
290
- The native control must be rendered
291
- before the visible label text due to https://bugs.webkit.org/show_bug.cgi?id=251951
295
+ The native control must be rendered with display:none instead of aria-hidden
296
+ to avoid nested interactive elements accessibility issues
292
297
*/ }
293
298
< input
294
299
type = "checkbox"
295
- aria-hidden = "true"
296
- tabindex = "-1"
300
+ style = { { display : 'none' } }
297
301
checked = { checked ? true : undefined }
298
302
disabled = { disabled }
299
303
id = { inputId }
@@ -307,10 +311,10 @@ export class Checkbox implements ComponentInterface {
307
311
< div
308
312
class = { {
309
313
'label-text-wrapper' : true ,
310
- 'label-text-wrapper-hidden' : el . textContent === '' ,
314
+ 'label-text-wrapper-hidden' : ! hasLabelContent ,
311
315
} }
312
316
part = "label"
313
- id = { inputId + '-lbl' }
317
+ id = { hasLabelId }
314
318
>
315
319
< slot > </ slot >
316
320
{ this . renderHintText ( ) }
0 commit comments