AsPhoneNumberInput
Introduction
MAsPhoneNumberInput is a phone number input component that automatically formats numbers through input masks, supporting custom masks and dial-code prefix display.
Usage
# represents a digit placeholder. The default mask is ### #### #### with dial code +86 (China mainland format).
<script setup lang="ts">
const value = ref("")
</script>
<template>
<MAsPhoneNumberInput v-model="value" />
</template>
dialCode Dial Code
Use dialCode to display a country or region dial code in front of the input:
<template>
<MAsPhoneNumberInput dial-code="+1" />
</template>
mask Mask
Use mask to adapt number formats for different countries. # represents a digit placeholder:
<template>
<MAsPhoneNumberInput mask="(###) ###-####" />
</template>
Examples
Inside UFieldGroup
When placed alongside a button inside UFieldGroup, they share size, border-radius, and border connection — ideal for combined dial operations:
<template>
<UFieldGroup size="xs">
<MAsPhoneNumberInput dial-code="+1" />
<UButton icon="i-lucide-phone-call" color="neutral" variant="subtle" />
</UFieldGroup>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
mask | '(###) ###-####' | string输入掩码格式, |
dialCode | '+86' | string区号前缀 |
id | string | |
name | string | |
placeholder | stringThe placeholder text when the input is empty. | |
color | 'primary' | "primary" | "secondary" | "info" | "success" | "warning" | "error" | "important" | "neutral" |
variant | 'outline' | "outline" | "soft" | "subtle" | "ghost" | "none" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
autocomplete | "on" | "off" | string & {} | |
autofocusDelay | number | |
defaultValue | T | |
modelModifiers | ModelModifiers | |
icon | anyDisplay an icon based on the | |
avatar | AvatarPropsDisplay an avatar on the left side. | |
leadingIcon | anyDisplay an icon on the left side. | |
trailingIcon | anyDisplay an icon on the right side. | |
loadingIcon | appConfig.ui.icons.loading | anyThe icon when the |
list | string | |
max | string | number | |
maxlength | string | number | |
min | string | number | |
minlength | string | number | |
pattern | string | |
readonly | false | true | "true" | "false" | |
step | string | number | |
modelValue | T | |
required | boolean | |
autofocus | boolean | |
disabled | boolean | |
highlight | booleanHighlight the ring color like a focus state. | |
fixed | booleanKeep the mobile text size on all breakpoints. | |
leading | booleanWhen | |
trailing | booleanWhen | |
loading | booleanWhen | |
ui | Record<string, ClassNameValue> & { root?: SlotClass; base?: SlotClass; leading?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailing?: SlotClass; trailingIcon?: SlotClass; dialCode?: SlotClass; } |
Emits
| Event | Type |
|---|---|
update:modelValue | [value: T] |
blur | [event: FocusEvent] |
change | [event: Event] |
Slots
| Slot | Type |
|---|---|
default | { ui: { root: (props?: Record<string, any>) => string; base: (props?: Record<string, any>) => string; leading: (props?: Record<string, any>) => string; leadingIcon: (props?: Record<string, any>) => string; leadingAvatar: (props?: Record<string, any>) => string; leadingAvatarSize: (props?: Record<string, any>) => string; trailing: (props?: Record<string, any>) => string; trailingIcon: (props?: Record<string, any>) => string; }; } |
trailing | { ui: { root: (props?: Record<string, any>) => string; base: (props?: Record<string, any>) => string; leading: (props?: Record<string, any>) => string; leadingIcon: (props?: Record<string, any>) => string; leadingAvatar: (props?: Record<string, any>) => string; leadingAvatarSize: (props?: Record<string, any>) => string; trailing: (props?: Record<string, any>) => string; trailingIcon: (props?: Record<string, any>) => string; }; } |
Theme
export default defineAppConfig({
ui: {
asPhoneNumberInput: {
slots: {
base: '',
leading: '',
dialCode: ''
},
variants: {
dialCode: {
true: {
base: 'ps-(--dial-code-length)',
leading: 'pointer-events-none text-muted'
}
}
}
}
}
})