Example
<wui-form>
<wui-form-group label="Phone number" label-for="wui-phone-number-input">
<wui-phone-number-input
id="wui-phone-number-input"
type="url"
/>
</wui-form-group>
</wui-form>
Good news! There is already a vue-file for the component you are looking for. You can find it in the implementation tab.
There will be a description regarding the different use cases of this component and what to consider when implementing it. If you have any questions, suggestions or ideas for improvement right now, please feel free to contact us directly.
via Slack: #wescale-wui-public
via Mail: wescale-wui@wescale.com >
Stay tuned!
import { WuiPhoneNumberInput } from "@wui/wui-vue/lib/phone-number-input";
Description
<wui-phone-number-inpute>
is a standalone input component to help the user enter a phone number and validate it according to the country.
Informations
This component uses <WuiCountrySelect>
and <WuiFormInput>
under the hood.
Important: for a better compatibility with all differents countries, use default-phone-number
prop to set and update the phone number and default-country-code
to update the country code. Updating the phone number and country code is no longer available when you change the value
(v-model).
default-phoner-number
: Use to set the init phone number (Ex: "2015550123")default-country-code
: Use to set the init country code (Ex: "US")value
(v-model) is the result of both (Ex: "+12015550123")
Features list
- Auto-detect country calling code with phone number provided
- You can set
preferred-countries
,ignored-countries
or haveonly-countries
- Multi options to getting country code : By default the component get the country code via the browser (disable it with
no-use-browser-locale
) or you can usefetch-country
to get the country code via https://ip2c.org/s (network needed) - you can usedefault-country-code
option instead to set one - Phone number formatting while typing
- You can search your country in list (open countries list & type your country name (feature of
<wui-form-select>
inside<wui-country-select>
)) - Keyboard accessibility (Arrow down, Arrow up: Countries list navigation - Escape: Close countries list) (feature of
<wui-form-select>
inside<wui-country-select>
) - Phone number example for each country in placeholder/label
- Auto focus phone number input after selecting country
- You can disable the flags -
no-flags
props
Keyboard accessibility
Keyboard functionality is completely inherited from the <wui-form-select>
component.
Entries | Actions |
---|---|
ArrowDown | Navigation down in countries list |
ArrowUp | Navigation up in countries list |
Escape | Close countries list |
All letters characters | Searching country name in countries list (should be open) |
Example
<template>
<wui-form-group>
<wui-phone-number
v-model="value"
@update="handleUpdatePhoneNumber"
default-country-code="DE"
default-phone-number="030577015550"
/>
<p class="m-t-15">Value: { value }</p>
Object:<br />
<pre class="m-t-15"><code>{ phoneNumberObject }</code></pre>
</wui-form-group>
</template>
<script>
export default {
data() {
return {
value: "",
phoneNumberObject: {},
};
},
methods: {
handleUpdatePhoneNumber(phoneNumberObject) {
this.phoneNumberObject = phoneNumberObject;
},
},
};
</script>
<!-- wui-phone-number-input.vue -->
Component reference
<wui-phone-number-input>
Component aliases
<wui-phone-number-input>
can also be used via the following aliases:
<wui-phone-number>
Note: component aliases are only available when importing all of WuiVue or using the component group plugin.
Properties
Property | Type | Default | Description |
---|---|---|---|
defaultCountryCode | String | null | Set the default country code (Ex: default-country-code="FR" ) |
defaultPhoneNumber | String | null | Set default phone number (Ex: default-phone-number="0658585858" ) |
disabled | Boolean | false | When set to true , disables the component's functionality and places it in a disabled state |
fetchCountry | Boolean | false | Fetch country code via https://ip2c.org/s - Network needed - (Do not use it with default-country-code options) |
focusPhoneInput | Boolean | false | Whether or not the phone number input field should be focused after selecting the country code. |
id | String | Used to set the id attribute on the rendered content | |
ignoredCountries | Array | Array[0] | Countries seleted are remove from the list - Ex : ignored-countries="['FR', 'BE', 'DE']" |
noCountrySelector | Boolean | false | The country selector is not shown, you can validate your phone number with the country code set |
noUseBrowserLocale | Boolean | false | Disable use of browser locale to init the country selector (usefull for Nuxt.JS) |
onlyCountries | Array | null | Only countries selected are in list - Ex : only-countries="['FR', 'BE', 'DE']" |
placeholder | String | null | Set placholder of the phone number input field |
preferredCountries | Array | null | Countries selected will be at the top of the list - Ex : preferred-countries="['FR', 'BE', 'DE']" |
showCodeOnList | Boolean | true | Show the country phone code in the list |
state | Boolean or String | null | Controls the validation state appearance of the component. true for valid, false for invalid, or null for no validation state |
value | String | The full phone number with country code |
Slots
Name | Description |
---|---|
append | Content to place after the phone number input |
prepend | Content to place before the country select |
Events
Event | Arguments | Description |
---|---|---|
blur | event - Native blur event | Emitted after the input field loses focus |
change | value - Current value of the phone number input field (just the number entered in the phone number input field | Change event triggered by user interaction. Emitted after any formatting (not including 'trim' or 'number' props) and after the v-model is updated |
focus | event - Native focus event | The focus event is fired when the user focuses the phone number input field |
input | value - Current full phone number combined from the country-select and phone-number input field (country code + phonbe number) | Input event triggered by user interaction. Emitted after any formatting (not including 'trim' or 'number' props) and after the v-model is updated |
update | results - Object with all parsed values | Emitted to update the v-model |
Importing individual components
You can import individual components into your project via the following named exports:
Component | Named Export |
---|---|
<wui-phone-number-input> | WuiPhoneNumberInput |
Example
import { WuiPhoneNumberInput } from "@wui/wui-vue/lib/phone-number-input";
Vue.component("wui-phone-number-input", WuiPhoneNumberInput);
Importing as a Vue.js plugin
This plugin includes all of the above listed individual components. Plugins also include any component aliases.
Named Export | Import Path |
---|---|
PhoneNumberPlugin | @wui/wui-vue/lib/phone-number |
Example
import { PhoneNumberPlugin } from "@wui/wui-vue/lib/phone-number-input";
Vue.use(PhoneNumberPlugin);