Skip to content

Commit 24c1c18

Browse files
committed
refactor(checkbox): move label ID to class property
1 parent 875cc38 commit 24c1c18

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/src/components/checkbox/checkbox.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type { CheckboxChangeEventDetail } from './checkbox-interface';
3131
})
3232
export class Checkbox implements ComponentInterface {
3333
private inputId = `ion-cb-${checkboxIds++}`;
34+
private inputLabelId = `${this.inputId}-lbl`;
3435
private helperTextId = `${this.inputId}-helper-text`;
3536
private errorTextId = `${this.inputId}-error-text`;
3637
private focusEl?: HTMLElement;
@@ -264,7 +265,6 @@ export class Checkbox implements ComponentInterface {
264265

265266
// Determine appropriate accessible name.
266267
const hasLabelContent = el.textContent !== '';
267-
const inputLabelId = inputId + '-lbl';
268268

269269
// The host element must have a checkbox role to ensure proper VoiceOver
270270
// support in Safari for accessibility.
@@ -274,7 +274,7 @@ export class Checkbox implements ComponentInterface {
274274
aria-checked={indeterminate ? 'mixed' : `${checked}`}
275275
aria-describedby={this.getHintTextID()}
276276
aria-invalid={this.getHintTextID() === this.errorTextId}
277-
aria-labelledby={hasLabelContent ? inputLabelId : null}
277+
aria-labelledby={hasLabelContent ? this.inputLabelId : null}
278278
aria-label={!hasLabelContent ? inheritedAttributes['aria-label'] || 'checkbox' : null}
279279
aria-disabled={disabled ? 'true' : null}
280280
tabindex={disabled ? undefined : 0}
@@ -315,7 +315,7 @@ export class Checkbox implements ComponentInterface {
315315
'label-text-wrapper-hidden': !hasLabelContent,
316316
}}
317317
part="label"
318-
id={inputLabelId}
318+
id={this.inputLabelId}
319319
>
320320
<slot></slot>
321321
{this.renderHintText()}

0 commit comments

Comments
 (0)