Skip to content

Commit 85b8cbf

Browse files
committed
fix(input): cleanup on input validation
1 parent 5760856 commit 85b8cbf

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

core/src/components/input/input.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ export class Input implements ComponentInterface {
413413
const hasIonInvalid = this.el.classList.contains('ion-invalid');
414414
const hasNgTouched = this.el.classList.contains('ng-touched');
415415
const hasNgInvalid = this.el.classList.contains('ng-invalid');
416-
416+
417417
// Return true if we have both touched and invalid states from either framework
418418
const isTouched = hasIonTouched || hasNgTouched;
419419
const isInvalid = hasIonInvalid || hasNgInvalid;
420-
420+
421421
return isTouched && isInvalid;
422422
}
423423

@@ -694,22 +694,12 @@ export class Input implements ComponentInterface {
694694
const { helperText, errorText, helperTextId, errorTextId, isInvalid } = this;
695695

696696
return [
697-
helperText && !isInvalid && (
698-
<div id={helperTextId} class="helper-text" aria-live="polite">
699-
{helperText}
700-
</div>
701-
),
702-
errorText && isInvalid && (
703-
<div
704-
id={errorTextId}
705-
class="error-text"
706-
aria-live="assertive"
707-
aria-atomic="true"
708-
role="alert"
709-
>
710-
{errorText}
711-
</div>
712-
),
697+
<div id={helperTextId} class="helper-text" aria-live="polite">
698+
{!isInvalid ? helperText : null}
699+
</div>,
700+
<div id={errorTextId} class="error-text" role="alert">
701+
{isInvalid ? errorText : null}
702+
</div>,
713703
];
714704
}
715705

core/src/components/textarea/textarea.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ export class Textarea implements ComponentInterface {
345345
const hasIonInvalid = this.el.classList.contains('ion-invalid');
346346
const hasNgTouched = this.el.classList.contains('ng-touched');
347347
const hasNgInvalid = this.el.classList.contains('ng-invalid');
348-
348+
349349
// Return true if we have both touched and invalid states from either framework
350350
const isTouched = hasIonTouched || hasNgTouched;
351351
const isInvalid = hasIonInvalid || hasNgInvalid;
352-
352+
353353
return isTouched && isInvalid;
354354
}
355355

@@ -697,22 +697,12 @@ export class Textarea implements ComponentInterface {
697697
const { helperText, errorText, helperTextId, errorTextId, isInvalid } = this;
698698

699699
return [
700-
helperText && !isInvalid && (
701-
<div id={helperTextId} class="helper-text" aria-live="polite">
702-
{helperText}
703-
</div>
704-
),
705-
errorText && isInvalid && (
706-
<div
707-
id={errorTextId}
708-
class="error-text"
709-
aria-live="assertive"
710-
aria-atomic="true"
711-
role="alert"
712-
>
713-
{errorText}
714-
</div>
715-
),
700+
<div id={helperTextId} class="helper-text" aria-live="polite">
701+
{!isInvalid ? helperText : null}
702+
</div>,
703+
<div id={errorTextId} class="error-text" role="alert">
704+
{isInvalid ? errorText : null}
705+
</div>,
716706
];
717707
}
718708

0 commit comments

Comments
 (0)