Skip to content

Commit e4f970f

Browse files
committed
fix(input): use correct setup for inputIds
1 parent 5a7ac87 commit e4f970f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

core/src/components/input/input.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { getCounterText } from './input.utils';
3333
export class Input implements ComponentInterface {
3434
private nativeInput?: HTMLInputElement;
3535
private inputId = `ion-input-${inputIds++}`;
36+
private helperTextId = `helper-text-${inputIds++}`;
37+
private errorTextId = `error-text-${inputIds++}`;
3638
private inheritedAttributes: Attributes = {};
3739
private isComposing = false;
3840
private slotMutationController?: SlotMutationController;
@@ -573,27 +575,27 @@ export class Input implements ComponentInterface {
573575
* Renders the helper text or error text values
574576
*/
575577
private renderHintText() {
576-
const { helperText, errorText } = this;
578+
const { helperText, errorText, helperTextId, errorTextId } = this;
577579

578580
return [
579-
<div id={HELPER_TEXT_ID} class="helper-text">
581+
<div id={helperTextId} class="helper-text">
580582
{helperText}
581583
</div>,
582-
<div id={ERROR_TEXT_ID} class="error-text">
584+
<div id={errorTextId} class="error-text">
583585
{errorText}
584586
</div>,
585587
];
586588
}
587589

588590
private getHintTextID(): string | undefined {
589-
const { el, helperText, errorText } = this;
591+
const { el, helperText, errorText, helperTextId, errorTextId } = this;
590592

591593
if (el.classList.contains('ion-touched') && el.classList.contains('ion-invalid') && errorText) {
592-
return ERROR_TEXT_ID;
594+
return errorTextId;
593595
}
594596

595597
if (helperText) {
596-
return HELPER_TEXT_ID;
598+
return helperTextId;
597599
}
598600

599601
return undefined;
@@ -721,8 +723,6 @@ export class Input implements ComponentInterface {
721723
const hasValue = this.hasValue();
722724
const hasStartEndSlots = el.querySelector('[slot="start"], [slot="end"]') !== null;
723725

724-
console.log('el', this.el);
725-
console.log('id', this.getHintTextID());
726726
/**
727727
* If the label is stacked, it should always sit above the input.
728728
* For floating labels, the label should move above the input if
@@ -801,7 +801,7 @@ export class Input implements ComponentInterface {
801801
onCompositionstart={this.onCompositionStart}
802802
onCompositionend={this.onCompositionEnd}
803803
aria-describedby={this.getHintTextID()}
804-
aria-invalid={this.getHintTextID() === ERROR_TEXT_ID}
804+
aria-invalid={this.getHintTextID() === this.errorTextId}
805805
{...this.inheritedAttributes}
806806
/>
807807
{this.clearInput && !readonly && !disabled && (
@@ -842,5 +842,3 @@ export class Input implements ComponentInterface {
842842
}
843843

844844
let inputIds = 0;
845-
const HELPER_TEXT_ID = `${'helper-text-' + inputIds}`;
846-
const ERROR_TEXT_ID = `${'error-text-' + inputIds}`;

0 commit comments

Comments
 (0)