Skip to content

Commit 979b93f

Browse files
committed
docs: added some input test cases
1 parent 3bb644b commit 979b93f

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

apps/docs/src/stories/Components/TextInput.story.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
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
@@ -101,9 +105,10 @@
101105
</template>
102106

103107
<script lang="ts" setup>
104-
import { ref } from "vue";
108+
import { ref, type Ref } from "vue";
105109
import ClockIcon from '@vue-patternfly/icons/clock-icon';
106110
107-
const text1 = ref('');
111+
const text1: Ref<string | null> = ref(null);
108112
const text2 = ref('');
113+
const number1 = ref(0);
109114
</script>

packages/core/src/components/TextInput.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
137161
defineExpose({
138162
...inputValidationData,
139163
input,

packages/core/src/input.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)