Skip to content

Commit

Permalink
Platform UI - phone number input bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: Kial Jinnah <kialj876@gmail.com>
  • Loading branch information
kialj876 committed Oct 30, 2024
1 parent 39208e0 commit ab18d15
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<script setup lang="ts">
const countryIso2 = defineModel<string>('countryIso2')
const countryCode = defineModel<string>('countryCode')
const number = defineModel<string>('number')
const extension = defineModel<string>('extension')
const props = defineProps({
name: { type: String, default: 'phone' },
number: { type: String, default: '' }
})
defineEmits(['update:number'])
defineProps({ name: { type: String, default: 'phone' } })
const northAmericaMask = '(###) ###-####'
const otherMask = '##############'
const inputMask = computed(() => countryCode.value === '1' ? northAmericaMask : otherMask)
const maskedValue = ref<string>(props.number)
const unmaskedValue = ref<string>('')
const maskedValue = ref<string>(number.value || '')
watch(number, (val) => {
maskedValue.value = val || ''
})
const phoneId = useId()
defineExpose({ unmaskedValue })
defineExpose({ number })
</script>
<template>
<div class="flex w-full max-w-bcGovInput flex-col gap-3 sm:flex-row">
Expand All @@ -44,7 +42,7 @@ defineExpose({ unmaskedValue })
<template #default="{ error }">
<UInput
v-model="maskedValue"
v-maska:unmaskedValue.unmasked="inputMask"
v-maska:number.unmasked="inputMask"
:aria-label="$t('label.phone.number')"
:color="number ? 'primary' : 'gray'"
:placeholder="$t('label.phone.number')"
Expand All @@ -54,7 +52,6 @@ defineExpose({ unmaskedValue })
size="lg"
type="tel"
data-testid="phone-number"
@input="$emit('update:number', unmaskedValue)"
/>
</template>
<template #error="{ error }">
Expand Down

0 comments on commit ab18d15

Please sign in to comment.