Skip to content
On this page

Phone Input

A Native Input dedicated to Mobile & Local Phone numbers, includes a beautiful country picker and a native input. Exports the national number, local number & country code for flexible & easier way to validate on the backend.

Preview & Playground 🖼️

Here you may find a preview of the component, with error & possible variants.

🏄 Click to expand the code
vue
<script setup lang="ts">
import { PhoneInput } from '@flavorly/vanilla-components'
import { ref } from 'vue'

const value = ref('+35191523813')
const valueCountry = 'PT'

const value2 = ref('+1915279172')
const value2Country = 'US'
</script>

<template>
  <PreviewWrapper>
    <PhoneInput
      v-model="value"
      :country-code="valueCountry"
      feedback="Im useful helper out here, choose wisely"
      :favorite-countries="['PT', 'ES', 'US']"
      country-placeholder="Pick your phone country"
      phone-placeholder="National Number"
    />

    <div class="flex items-center justify-center mx-auto text-center mt-2">
      <pre class="text-xs">{{ JSON.stringify(value) }}</pre>
    </div>

    <div class="h-1 my-5" />

    <!-- Regular -->
    <PhoneInput
      v-model="value2"
      :country-code="value2Country"
      feedback="Im useful helper out here, choose wisely"
      errors="Sorry but your phone number looks to be invalid."
      country-placeholder="Pick your phone country"
      phone-placeholder="National Number"
    />

    <div class="flex items-center justify-center mx-auto text-center mt-2">
      <pre class="text-xs">{{ JSON.stringify(value2) }}</pre>
    </div>
  </PreviewWrapper>
</template>

Props 📥

Props available for this component extending the default variant & global props.

PropDescriptionAccepted ValuesDefault
modelValueThe value for the elementAny, Valid Country ISO Codeundefined
countryCodeThe country code in ISO formatAny, Valid Country ISO Codeundefined
phonePlaceholderThe placeholder for the phone number inputStringYour national number
countryPlaceholderThe placeholder for the country inputStringYour country
favoriteCountriesArray of favorite countries to preloadArray['us','gb','pt','fr','de']
labelWithDialCodeIf you want the label with a dial codeBooleanfalse
labelWithCountryCodeIf you want the label with country codeBooleanfalse
searchBoxPlaceholderPlaceholder for the Search BoxstringSearch here
noResultsTextWhen no results are found, the text to displaystringSorry...
searchingTextText to display while searchingstringPlease wait...
loadingClosedPlaceholderWhen loading but dropdown closedstringLoading please wait...
loadingMoreResultsTextText while is pulling for next pagesstringLoading more options...
minimumInputLengthTextA function or a number with the minimum chars to searchString, Function3

Slots 🧬

Current slots available for this component are the following:

Slot before

Slot to override or pre-pend to the component before the component, ex: icon, etc.

AttributeDescriptionType
classNameClasses injectedString

Slot after

Slot to override or append to the component before the component, ex: icon, etc.

Attributes specially injected to the after slot for some inputs ( Ex: Password )

AttributeDescriptionType
hasErrorsIf the field has errorsBoolean
typeType of inputString
showingPasswordIf the password showing is toggledBoolean

Slot errors

Slot that holds the error messages when the component errors prop is defined.

AttributeDescriptionType
errorsThe errors being injected[String, Array]
hasErrorsIf the field has errorsBoolean

Slot feedback

Slot that holds the feedback messages when the component feedback prop is defined. When showing errors the feedback will be hidden by default, and vice-versa.

AttributeDescriptionType
errorsThe errors being injected[String, Array, Undefined]
feedbackThe feedback message[String, Undefined]

Events 🚇

Here you may find the events emitted by this component.

EventDescriptionValue
update:modelValueWhen the value changesany

| update:countryDialCode | The country dial code | string | | update:countryCode | The ISO country code | string | | update:phoneNumberNational | Phone number in national format | string | | update:phoneNumberInternational | Phone number in International format | string |

Released under the MIT License.