11import type { ComponentInterface , EventEmitter } from '@stencil/core' ;
2- import { Build , Component , Element , Event , Host , Method , Prop , State , h , forceUpdate } from '@stencil/core' ;
2+ import { Build , Component , Element , Event , Host , Method , Prop , State , h } from '@stencil/core' ;
33import { checkInvalidState } from '@utils/forms' ;
44import type { Attributes } from '@utils/helpers' ;
55import { inheritAriaAttributes , renderHiddenInput } from '@utils/helpers' ;
@@ -127,6 +127,8 @@ export class Checkbox implements ComponentInterface {
127127 */
128128 @State ( ) isInvalid = false ;
129129
130+ @State ( ) private hasLabelContent = false ;
131+
130132 @State ( ) private hintTextId ?: string ;
131133
132134 /**
@@ -266,7 +268,7 @@ export class Checkbox implements ComponentInterface {
266268 } ;
267269
268270 private onSlotChange = ( ) => {
269- forceUpdate ( this ) ;
271+ this . hasLabelContent = this . el . textContent !== '' ;
270272 } ;
271273
272274 private getHintTextId ( ) : string | undefined {
@@ -330,7 +332,6 @@ export class Checkbox implements ComponentInterface {
330332 } = this ;
331333 const mode = getIonMode ( this ) ;
332334 const path = getSVGPath ( mode , indeterminate ) ;
333- const hasLabelContent = el . textContent !== '' ;
334335
335336 renderHiddenInput ( true , el , name , checked ? value : '' , disabled ) ;
336337
@@ -342,7 +343,7 @@ export class Checkbox implements ComponentInterface {
342343 aria-checked = { indeterminate ? 'mixed' : `${ checked } ` }
343344 aria-describedby = { this . hintTextId }
344345 aria-invalid = { this . isInvalid ? 'true' : undefined }
345- aria-labelledby = { hasLabelContent ? this . inputLabelId : null }
346+ aria-labelledby = { this . hasLabelContent ? this . inputLabelId : null }
346347 aria-label = { inheritedAttributes [ 'aria-label' ] || null }
347348 aria-disabled = { disabled ? 'true' : null }
348349 aria-required = { required ? 'true' : undefined }
@@ -380,7 +381,7 @@ export class Checkbox implements ComponentInterface {
380381 < div
381382 class = { {
382383 'label-text-wrapper' : true ,
383- 'label-text-wrapper-hidden' : ! hasLabelContent ,
384+ 'label-text-wrapper-hidden' : ! this . hasLabelContent ,
384385 } }
385386 part = "label"
386387 id = { this . inputLabelId }
0 commit comments