Skip to content

Commit

Permalink
fix(input-number): null becoming string and causing warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Jan 11, 2023
1 parent 768aba0 commit 6b05217
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/components/SInputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,32 @@ const props = defineProps<{
align?: Align
separator?: boolean
disabled?: boolean
modelValue: number | null
value?: number | null
modelValue?: number | null
displayValue?: string | null
hideError?: boolean
validation?: Validatable
}>()
const emit = defineEmits<{
(e: 'update:modelValue', value: number | null): void
(e: 'input', value: number | null): void
}>()
const _value = computed(() => {
return props.modelValue !== undefined
? props.modelValue
: props.value !== undefined ? props.value : null
})
const valueWithSeparator = computed(() => {
if (isNullish(props.modelValue)) {
if (isNullish(_value.value)) {
return null
}
return props.modelValue >= 100000000000000000000
return _value.value >= 100000000000000000000
? 'The number is too big'
: props.modelValue.toLocaleString('en-US', { maximumSignificantDigits: 20 })
: _value.value.toLocaleString('en-US', { maximumSignificantDigits: 20 })
})
const displayValue = computed(() => {
Expand All @@ -48,7 +56,9 @@ const displayValue = computed(() => {
})
function emitUpdate(value: string | null) {
emit('update:modelValue', isNullish(value) ? null : Number(value))
const v = isNullish(value) ? null : Number(value)
emit('update:modelValue', v)
emit('input', v)
}
</script>

Expand All @@ -66,8 +76,9 @@ function emitUpdate(value: string | null) {
:disabled="disabled"
:hide-error="hideError"
:display-value="displayValue"
:model-value="String(modelValue)"
:model-value="_value === null ? null : String(_value)"
:validation="validation"
@update:model-value="emitUpdate"
@input="emitUpdate"
/>
</template>
5 changes: 4 additions & 1 deletion lib/components/SInputText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const props = defineProps<{
const emit = defineEmits<{
(e: 'update:modelValue', value: string | null): void
(e: 'input', value: string | null): void
(e: 'blur', value: string | null): void
(e: 'enter', value: string | null): void
}>()
Expand Down Expand Up @@ -62,7 +63,9 @@ function emitBlur(e: FocusEvent): void {
}
function emitInput(e: Event): void {
emit('update:modelValue', getValue(e))
const v = getValue(e)
emit('update:modelValue', v)
emit('input', v)
}
function emitEnter(e: KeyboardEvent): void {
Expand Down

0 comments on commit 6b05217

Please sign in to comment.