Skip to content

Commit 9f88586

Browse files
committed
preserve text input value type
1 parent 2629cea commit 9f88586

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/components/TextInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { computed, inject, ref } from "vue"
4242
import { input, filterClass } from './css'
4343
import { textInputValue } from '@/use/utils'
4444
45-
const value = (e:EventTarget|null) => (e as HTMLInputElement).value //workaround IDE type-check error
45+
const value = (e:EventTarget|null) => textInputValue(useType.value, (e as HTMLInputElement).value) //workaround IDE type-check error
4646
4747
const props = defineProps<TextInputProps>()
4848

src/use/utils.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,17 @@ export function timeInputFormat(s?:string|number|Date|null) { return s == null ?
2727
export function textInputValue(type:string, value:any) {
2828
if (Sole.config.inputValue)
2929
return Sole.config.inputValue(type,value)
30-
let ret = type === 'date'
31-
? dateInputFormat(value)
32-
: type === 'datetime-local'
33-
? dateTimeInputFormat(value)
34-
: type === 'time'
35-
? timeInputFormat(value)
36-
: value
37-
const t = typeof ret
38-
ret = ret == null
39-
? ''
40-
: t == 'boolean' || t == 'number'
41-
? `${ret}`
42-
: ret
43-
return ret
30+
31+
if (type === 'date') {
32+
return dateInputFormat(value)
33+
} else if (type === 'datetime-local') {
34+
return dateTimeInputFormat(value)
35+
} else if (type === 'time') {
36+
return timeInputFormat(value)
37+
} else if (type === 'number' || type === 'range') {
38+
return Number(value)
39+
}
40+
return value
4441
}
4542

4643

0 commit comments

Comments
 (0)