1
1
import { shallowRef , toValue } from 'vue' ;
2
2
import { InputEvents , Reactivify } from '../types' ;
3
- import { propsToValues , useCaptureProps } from '../utils/common' ;
3
+ import { normalizeProps , propsToValues , useCaptureProps } from '../utils/common' ;
4
4
import { TextControlProps } from './types' ;
5
5
import { useInputValidity } from '../validation' ;
6
6
import { FieldState , useFieldStateInjection } from '../useFieldState' ;
@@ -12,13 +12,19 @@ interface FormControlContext {
12
12
state ?: FieldState < string | undefined > ;
13
13
}
14
14
15
- export function useTextControl ( props : Reactivify < TextControlProps > , ctx ?: FormControlContext ) {
15
+ export function useTextControl ( _props : Reactivify < TextControlProps > , ctx ?: FormControlContext ) {
16
16
const inputEl = shallowRef < HTMLInputElement > ( ) ;
17
+ const props = normalizeProps ( _props ) ;
17
18
const field = ctx ?. field ?? useFormFieldInjection ( ) ;
18
19
const state = ctx ?. state ?? useFieldStateInjection < string | undefined > ( ) ;
19
20
20
21
if ( state ) {
21
- useInputValidity ( { inputEl, field : state , disableHtmlValidation : props . disableHtmlValidation } ) ;
22
+ useInputValidity ( {
23
+ inputEl,
24
+ field : state ,
25
+ disableHtmlValidation : props . disableHtmlValidation ,
26
+ events : ( ) => toValue ( props . validateOn ) ?? [ 'change' , 'blur' ] ,
27
+ } ) ;
22
28
}
23
29
24
30
if ( field ) {
0 commit comments