Skip to content

Accessibility: Partial

Translations: Not Needed

Input Phone

A component for inputting and validating international phone numbers with country code selection

Basic Usage

Vue
html
<template>
  <HLInputPhone v-model:value="phone" v-model:countryCode="countryCode" />
</template>

<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const phone = ref('+91845403166')
  const countryCode = ref('IN')
</script>

With Icon

Vue
html
<HLInputPhone v-model:value="phone" v-model:countryCode="countryCode">
  <template #suffix>
    <HLIcon>
      <MessageQuestionCircleIcon class="w-4" />
    </HLIcon>
  </template>
</HLInputPhone>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const phone = ref('+91845403166')
  const countryCode = ref('IN')
</script>

Sizes

Vue
html
<template>
  <HLInputPhone size="lg" placeholder="Large size" />
  <HLInputPhone size="md" placeholder="Medium size" />
  <HLInputPhone size="sm" placeholder="Small size" />
  <HLInputPhone size="xs" placeholder="Extra small size" />
  <HLInputPhone size="2xs" placeholder="2x Extra small size" />
  <HLInputPhone size="3xs" placeholder="3x Extra small size" />
</template>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const phone = ref('+91845403166')
  const countryCode = ref('IN')
</script>

Disabled State

(201) 555-0123
Vue
html
<template>
  <HLInputPhone id="input-phone-disabled" disabled />
</template>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
</script>

With Disabled Country Picker

Vue
html
<template>
  <HLInputPhone id="input-phone-no-country" disableCountryPicker v-model:value="phone" />
</template>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const phone = ref('+91845403166')
</script>

Format Types

National format: (415) 555-2671

Try typing: 4155552671

International format: +1 415 555 2671

Try typing: 4155552671
html
<template>
  <HLInputPhone
    v-model:value="nationalPhone"
    v-model:countryCode="nationalCountryCode"
    format="national"
    placeholder="Try typing: 4155552671"
    @nationalFormat="handleNationalFormat"
  />
</template>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const nationalPhone = ref('')
  const nationalCountryCode = ref('US')
</script>
html
<template>
  <HLInputPhone
    v-model:value="internationalPhone"
    v-model:countryCode="internationalCountryCode"
    format="international"
    placeholder="Try typing: 4155552671"
    @internationalFormat="handleInternationalFormat"
  />
</template>
<script setup lang="ts">
  import { HLInputPhone } from '@platform-ui/highrise'
  import { ref } from 'vue'
  const internationalPhone = ref('')
  const internationalCountryCode = ref('US')
</script>

With Form Validation

html
<HLForm ref="formRef" :rules="rules">
  <HLFormItem path="phone">
    <HLInputPhone v-model:value="phone" v-model:countryCode="countryCode" @isValid="isFormPhoneValid = $event" />
  </HLFormItem>
</HLForm>
ts
const formRef = ref(null)
const phone = ref('+91845403166')
const countryCode = ref('IN')
const isFormPhoneValid = ref(true)
const rules = {
  phone: {
    required: true,
    validator(_, updatedPhone) {
      console.log('updatedPhone: ', updatedPhone)
      if (isFormPhoneValid.value) return true
      if (!updatedPhone) {
        return new Error('Phone number is required')
      }
      if (/[a-zA-Z]/g.test(updatedPhone)) {
        return new Error('Phone number can only contain numbers')
      }
      if (!isFormPhoneValid.value) {
        return new Error('Please enter a valid phone number')
      }
    },
    trigger: ['input', 'blur', 'change', 'focus'],
  },
}

Event Testing

This example shows how to test various input events. Try the following:

  • Type a number and click the clear icon (×) to test the @clear event
  • Select text in the input to test the @select event
  • Type a long number to make the input scrollable and scroll to test the @scroll-to event

Event Log:

No events logged yet. Try the actions above.
Vue
html
<script setup>
  const eventLog = ref([])
  const addEventLog = event => {
    eventLog.value.unshift({ event, timestamp: new Date().toLocaleTimeString() })
    // Keep only last 5 events
    if (eventLog.value.length > 5) {
      eventLog.value.pop()
    }
  }
</script>

<template>
  <HLInputPhone
    v-model:value="phone"
    v-model:countryCode="countryCode"
    placeholder="Test events here..."
    @clear="addEventLog('Clear event triggered')"
    @select="addEventLog('Select event triggered')"
    @scroll-to="addEventLog('Scroll event triggered')"
  />
  <div class="text-sm">
    <p class="font-bold mb-2">Event Log:</p>
    <div v-if="eventLog.length === 0" class="text-gray-500">No events logged yet. Try the actions above.</div>
    <div v-for="(log, index) in eventLog" :key="index" class="text-gray-700">{{ log.timestamp }}: {{ log.event }}</div>
  </div>
</template>

Imports

ts
import { HLInputPhone, HLForm, HLFormItem } from '@platform-ui/highrise'

Props

NameTypeDefaultDescription
id *string | undefinedundefinedUnique identifier for the input
countryCodestring | undefinedundefinedTwo-letter country code (ISO 3166-1 alpha-2).
valuestring | undefinedundefinedPhone number value
disabledbooleanfalseWhether the input is disabled
disableCountryPickerbooleanfalseWhether to disable the country selection dropdown
autocompletebooleanfalseEnable/disable browser autocomplete
size'lg' | 'md' | 'sm' | 'xs' | '2xs' | '3xs''sm'Size of the input
format'national' | 'international''nationalFormat'Phone number format

Emits

NameParametersDescription
@internationalFormat(phone: string)Emitted when phone number is formatted internationally
@nationalFormat(phone: string)Emitted when phone number is formatted nationally
@isValid(valid: boolean)Emitted when phone number validation status changes
@update:countryCode(code: string)Emitted when country code changes
@update:value(value: string)Emitted when phone number value changes
@focus(event: FocusEvent)Emitted when the input receives focus
@blur(event: FocusEvent)Emitted when the input loses focus
@scrollTo(event: Event)Emitted when scrolling occurs in the input

Slots

NameDescription
suffixContent to show after the input

Methods

NameParametersReturnsDescription
focus() => voidvoidFocus the input number element
blur() => voidvoidBlur the input number element
clear() => voidvoidClear the input number element
select() => voidvoidSelect the input number element
scrollTo() => voidvoidScroll to the input number element