Skip to content

Commit 94639f8

Browse files
committed
fix(checkbox): add hasLabelContent state
1 parent 03bc9f5 commit 94639f8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

core/src/components/checkbox/checkbox.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 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';
33
import { checkInvalidState } from '@utils/forms';
44
import type { Attributes } from '@utils/helpers';
55
import { 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

Comments
 (0)