Skip to content

Commit 98edded

Browse files
committed
refactor(textarea): use validity utils
1 parent 641f250 commit 98edded

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

core/src/components/textarea/textarea.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
writeTask,
1616
} from '@stencil/core';
1717
import type { NotchController } from '@utils/forms';
18-
import { createNotchController } from '@utils/forms';
18+
import { createNotchController, checkInvalidState } from '@utils/forms';
1919
import type { Attributes } from '@utils/helpers';
2020
import { inheritAriaAttributes, debounceEvent, inheritAttributes, componentOnReady } from '@utils/helpers';
2121
import { createSlotMutationController } from '@utils/slot-mutation-controller';
@@ -335,16 +335,6 @@ export class Textarea implements ComponentInterface {
335335
}
336336
}
337337

338-
/**
339-
* Checks if the textarea is in an invalid state based on Ionic validation classes
340-
*/
341-
private checkValidationState(): boolean {
342-
const hasIonTouched = this.el.classList.contains('ion-touched');
343-
const hasIonInvalid = this.el.classList.contains('ion-invalid');
344-
345-
return hasIonTouched && hasIonInvalid;
346-
}
347-
348338
connectedCallback() {
349339
const { el } = this;
350340
this.slotMutationController = createSlotMutationController(el, ['label', 'start', 'end'], () => forceUpdate(this));
@@ -357,7 +347,7 @@ export class Textarea implements ComponentInterface {
357347
// Watch for class changes to update validation state
358348
if (Build.isBrowser && typeof MutationObserver !== 'undefined') {
359349
this.validationObserver = new MutationObserver(() => {
360-
const newIsInvalid = this.checkValidationState();
350+
const newIsInvalid = checkInvalidState(this.el);
361351
if (this.isInvalid !== newIsInvalid) {
362352
this.isInvalid = newIsInvalid;
363353
// Force a re-render to update aria-describedby immediately
@@ -372,7 +362,7 @@ export class Textarea implements ComponentInterface {
372362
}
373363

374364
// Always set initial state
375-
this.isInvalid = this.checkValidationState();
365+
this.isInvalid = checkInvalidState(this.el);
376366

377367
this.debounceChanged();
378368
if (Build.isBrowser) {

core/src/utils/forms/validity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type FormElement = HTMLIonInputElement | HTMLIonSelectElement;
1+
type FormElement = HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSelectElement;
22

33
/**
44
* Checks if the form element is in an invalid state based on

0 commit comments

Comments
 (0)