File tree Expand file tree Collapse file tree 3 files changed +37
-8
lines changed
apps/docs/src/stories/Components Expand file tree Collapse file tree 3 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 1010 <pf-text-input v-model =" text1" aria-label =" text input example" />
1111 </story-canvas >
1212
13+ <story-canvas title =" Numeric" >
14+ <pf-text-input v-model =" number1" type =" number" aria-label =" text input example" />
15+ </story-canvas >
16+
1317 <story-canvas title =" Disabled" >
1418 <pf-text-input
1519 disabled
101105</template >
102106
103107<script lang="ts" setup>
104- import { ref } from " vue" ;
108+ import { ref , type Ref } from " vue" ;
105109import ClockIcon from ' @vue-patternfly/icons/clock-icon' ;
106110
107- const text1 = ref (' ' );
111+ const text1: Ref < string | null > = ref (null );
108112const text2 = ref (' ' );
113+ const number1 = ref (0 );
109114 </script >
Original file line number Diff line number Diff line change @@ -115,8 +115,8 @@ const {
115115 value,
116116 effectiveValidated,
117117 onBlur,
118- onChange,
119- onInput,
118+ onChange : commonOnChange ,
119+ onInput : commonOnInput ,
120120 onInvalid,
121121 onKeyUp,
122122 ... inputValidationData
@@ -134,6 +134,30 @@ function focus() {
134134 input .value ?.focus ();
135135}
136136
137+ function onChange(event : Event ) {
138+ if (! input .value ) {
139+ return ;
140+ }
141+ const value = input .value .value ;
142+ if (props .type === ' number' ) {
143+ commonOnChange (event , value ? parseFloat (value ) : null );
144+ } else {
145+ commonOnChange (event , value );
146+ }
147+ }
148+
149+ function onInput(event : InputEvent ) {
150+ if (! input .value ) {
151+ return ;
152+ }
153+ const value = input .value .value ;
154+ if (props .type === ' number' ) {
155+ commonOnInput (event , value ? parseFloat (value ) : null );
156+ } else {
157+ commonOnInput (event , value );
158+ }
159+ }
160+
137161defineExpose ({
138162 ... inputValidationData ,
139163 input ,
Original file line number Diff line number Diff line change @@ -108,10 +108,10 @@ export function useInputValidation({
108108 reportValidity,
109109 setCustomValidity,
110110
111- onInput ( event : InputEvent ) {
111+ onInput ( event : InputEvent , value ?: any ) {
112112 instance ?. $emit ( 'input' , event ) ;
113113 if ( ! modifiers . lazy ) {
114- value . value = ( event . target as InputElement ) . value ;
114+ value . value = value ?? ( event . target as InputElement ) . value ;
115115 }
116116 if ( autoValidate === 'input' ) {
117117 reportValidity ( ) ;
@@ -129,10 +129,10 @@ export function useInputValidation({
129129 }
130130 } ,
131131
132- onChange ( event : Event ) {
132+ onChange ( event : Event , value ?: any ) {
133133 instance ?. $emit ( 'change' , event ) ;
134134 if ( modifiers . lazy ) {
135- value . value = ( event . target as InputElement ) . value ;
135+ value . value = value ?? ( event . target as InputElement ) . value ;
136136 }
137137 if ( autoValidate === 'change' ) {
138138 reportValidity ( ) ;
You can’t perform that action at this time.
0 commit comments