File tree Expand file tree Collapse file tree 4 files changed +4
-50
lines changed
tests/e2e/specs/components Expand file tree Collapse file tree 4 files changed +4
-50
lines changed Original file line number Diff line number Diff line change @@ -68,24 +68,14 @@ const Inputs: React.FC<InputsProps> = () => {
6868
6969 const [ touched , setTouched ] = useState ( {
7070 input : false ,
71- inputOtp : false ,
7271 textarea : false ,
7372 } ) ;
7473
7574 const getValidationClasses = ( fieldName : keyof typeof touched , value : string | number | null | undefined ) => {
7675 const isTouched = touched [ fieldName ] ;
77- let isValid = false ;
7876
79- // Handle ion-input-otp which has multiple inputs
80- if ( fieldName === 'inputOtp' ) {
81- // input-otp needs to check if all inputs are filled
82- // (value length equals component length)
83- const valueStr = String ( value || '' ) ;
84- isValid = valueStr . length === 4 ;
85- } else {
86- const isEmpty = value === '' || value === null || value === undefined ;
87- isValid = ! isEmpty ;
88- }
77+ const isEmpty = value === '' || value === null || value === undefined ;
78+ const isValid = ! isEmpty ;
8979
9080 // Always return validation classes
9181 // ion-touched is only added on blur
@@ -115,7 +105,6 @@ const Inputs: React.FC<InputsProps> = () => {
115105 setSelect ( 'apples' ) ;
116106 setTouched ( {
117107 input : false ,
118- inputOtp : false ,
119108 textarea : false ,
120109 } ) ;
121110 } ;
@@ -207,9 +196,6 @@ const Inputs: React.FC<InputsProps> = () => {
207196 < IonInputOtp
208197 value = { inputOtp }
209198 onIonInput = { ( e : IonInputOtpCustomEvent < InputOtpInputEventDetail > ) => setInputOtp ( e . detail . value ?? '' ) }
210- onIonBlur = { ( ) => setTouched ( prev => ( { ...prev , inputOtp : true } ) ) }
211- className = { getValidationClasses ( 'inputOtp' , inputOtp ) }
212- required
213199 > </ IonInputOtp >
214200 </ IonItem >
215201
Original file line number Diff line number Diff line change @@ -80,15 +80,6 @@ describe('Inputs', () => {
8080
8181 cy . get ( 'ion-textarea' ) . shadow ( ) . find ( 'textarea' ) . focus ( ) . blur ( ) ;
8282 cy . get ( 'ion-textarea' ) . should ( 'have.class' , 'ion-invalid' ) ;
83-
84- cy . get ( 'ion-input-otp input' ) . first ( ) . focus ( ) . blur ( ) ;
85- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-invalid' ) ;
86- } ) ;
87-
88- it ( 'should show invalid state for required input-otp when partially filled' , ( ) => {
89- cy . get ( 'ion-input-otp input' ) . first ( ) . focus ( ) . blur ( ) ;
90- cy . get ( 'ion-input-otp input' ) . eq ( 0 ) . type ( '12' , { scrollBehavior : false } ) ;
91- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-invalid' ) ;
9283 } ) ;
9384
9485 it ( 'should show valid state for required inputs when filled' , ( ) => {
@@ -97,9 +88,6 @@ describe('Inputs', () => {
9788
9889 cy . get ( 'ion-textarea' ) . shadow ( ) . find ( 'textarea' ) . type ( 'Test value' , { scrollBehavior : false } ) ;
9990 cy . get ( 'ion-textarea' ) . should ( 'have.class' , 'ion-valid' ) ;
100-
101- cy . get ( 'ion-input-otp input' ) . eq ( 0 ) . type ( '1234' , { scrollBehavior : false } ) ;
102- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-valid' ) ;
10391 } ) ;
10492 } ) ;
10593} )
Original file line number Diff line number Diff line change 4242 </ion-item >
4343
4444 <ion-item >
45- <ion-input-otp v-model =" inputOtp" required @ionBlur = " handleValidation " @ionInput = " handleValidation " ></ion-input-otp >
45+ <ion-input-otp v-model =" inputOtp" ></ion-input-otp >
4646 </ion-item >
4747
4848 <ion-item >
@@ -181,16 +181,8 @@ const setIonicClasses = (element: HTMLElement, isBlurEvent: boolean) => {
181181 requestAnimationFrame (() => {
182182 let isValid = false ;
183183
184- // Handle ion-input-otp which has multiple inputs
185- if (element .tagName === ' ION-INPUT-OTP' ) {
186- const ionInputOtp = element as any ;
187- const value = ionInputOtp .value || ' ' ;
188- const length = ionInputOtp .length || 4 ;
189- // input-otp needs to check if all inputs are filled
190- // (value length equals component length)
191- isValid = value .length === length ;
192184 // Handle ion-textarea which uses shadow DOM
193- } else if (element .tagName === ' ION-TEXTAREA' ) {
185+ if (element .tagName === ' ION-TEXTAREA' ) {
194186 const nativeTextarea = element .shadowRoot ?.querySelector (' textarea' ) as HTMLTextAreaElement | null ;
195187 if (nativeTextarea ) {
196188 isValid = nativeTextarea .checkValidity ();
Original file line number Diff line number Diff line change @@ -77,15 +77,6 @@ describe('Inputs', () => {
7777 cy . get ( 'ion-textarea' ) . shadow ( ) . find ( 'textarea' ) . focus ( ) ;
7878 cy . get ( 'ion-textarea' ) . blur ( ) ;
7979 cy . get ( 'ion-textarea' ) . should ( 'have.class' , 'ion-invalid' ) ;
80-
81- cy . get ( 'ion-input-otp input' ) . first ( ) . focus ( ) . blur ( ) ;
82- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-invalid' ) ;
83- } ) ;
84-
85- it ( 'should show invalid state for required input-otp when partially filled' , ( ) => {
86- cy . get ( 'ion-input-otp input' ) . first ( ) . focus ( ) . blur ( ) ;
87- cy . get ( 'ion-input-otp input' ) . eq ( 0 ) . type ( '12' , { scrollBehavior : false } ) ;
88- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-invalid' ) ;
8980 } ) ;
9081
9182 it ( 'should show valid state for required inputs when filled' , ( ) => {
@@ -94,9 +85,6 @@ describe('Inputs', () => {
9485
9586 cy . get ( 'ion-textarea' ) . shadow ( ) . find ( 'textarea' ) . type ( 'Test value' , { scrollBehavior : false } ) ;
9687 cy . get ( 'ion-textarea' ) . should ( 'have.class' , 'ion-valid' ) ;
97-
98- cy . get ( 'ion-input-otp input' ) . eq ( 0 ) . type ( '1234' , { scrollBehavior : false } ) ;
99- cy . get ( 'ion-input-otp' ) . should ( 'have.class' , 'ion-valid' ) ;
10088 } ) ;
10189 } ) ;
10290} )
You can’t perform that action at this time.
0 commit comments