Skip to content

Keyboard Virtual Keyboard

Virtual numeric keyboard, used for entering numbers, passwords, ID cards, or license plates, etc.

Basic Usage

You can control whether the keyboard is displayed via v-model:visible.

html
<wd-cell title="Default Keyboard" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" @input="onInput" @delete="onDelete"></wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Component Type

Keyboard with Sidebar

Set mode property to custom to display the keyboard's right sidebar, commonly used for entering amounts.

html
<wd-cell title="Keyboard with Sidebar" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" mode="custom" extra-key="." close-text="Done" @input="onInput" @delete="onDelete"></wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

ID Card Keyboard

You can set the bottom-left key content via extra-key property. For example, when entering an ID card number, you can set extra-key to X.

html
<wd-cell title="ID Card Keyboard" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" extra-key="X" close-text="Done" @input="onInput" @delete="onDelete" />
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

License Plate Keyboard

Set mode property to car to display the license plate keyboard, commonly used for entering license plate numbers.

html
<wd-cell title="License Plate Keyboard" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" mode="car" @input="onInput" @delete="onDelete"></wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Component Variants

License Plate Keyboard Language Control

You can control the language mode of the license plate keyboard via car-lang property, supporting Chinese provinces (zh) and English letters (en). You can control whether to automatically switch languages via auto-switch-lang property.

html
<!-- Controlled Mode: Manual language switching -->
<wd-cell title="License Plate Keyboard (Controlled)" :value="value" is-link @click="showKeyBoard" />

<wd-keyboard v-model="value" v-model:visible="visible" v-model:car-lang="lang" mode="car" @input="onInput" @delete="onDelete"></wd-keyboard>

<!-- Uncontrolled Mode: Enable auto-switch -->
<wd-cell title="License Plate Keyboard (Uncontrolled)" :value="value2" is-link @click="showKeyBoard2" />

<wd-keyboard v-model="value2" v-model:visible="visible2" mode="car" auto-switch-lang @input="onInput" @delete="onDelete"></wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)
const visible2 = ref<boolean>(false)
const value = ref<string>('')
const value2 = ref<string>('')
const lang = ref<'zh' | 'en'>('zh')

function showKeyBoard() {
  visible.value = true
}

function showKeyBoard2() {
  visible2.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Keyboard with Title

You can set the keyboard title via title property.

html
<wd-cell title="Keyboard with Title" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" title="Enter Password" extra-key="." close-text="Done" @input="onInput" @delete="onDelete" />
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Use Slot for Custom Title

html
<wd-cell title="Use Slot for Custom Title" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" extra-key="." close-text="Done" @input="onInput" @delete="onDelete">
  <template #title>
    <text style="color: red">Custom Title</text>
  </template>
</wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Multiple Extra Keys

When mode is custom, it supports configuring two extra-keys in array form.

html
<wd-cell title="Multiple Extra Keys" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" mode="custom" :extra-key="['00', '.']" close-text="Done" @input="onInput" @delete="onDelete" />
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Random Numeric Keyboard

You can randomly sort the numeric keyboard via random-key-order property, commonly used for high security scenarios.

html
<wd-cell title="Random Numeric Keyboard" is-link @click="showKeyBoard" />

<wd-keyboard v-model:visible="visible" random-key-order @input="onInput" @delete="onDelete" />
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Special Usage

Two-way Binding

You can bind the keyboard's current input value via v-model, and limit the input length via maxlength property.

html
<wd-cell title="Two-way Binding" :value="value1" is-link @click="showKeyBoard" />
<wd-keyboard
  v-model="value1"
  :maxlength="6"
  v-model:visible="visible"
  title="Keyboard Title"
  extra-key="."
  close-text="Done"
  @input="onInput"
  @delete="onDelete"
></wd-keyboard>
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)
const value1 = ref<string>('')

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Show Mask Overlay

hideOnClickOutside controls whether the keyboard popup has a mask. modal controls whether the mask is transparent.

Tip

Currently modal only controls whether the mask is transparent. hideOnClickOutside controls whether the popup has a mask. When there is a mask, clicking the mask can close the keyboard. However, when the keyboard is expanded, you must click the mask to close the current keyboard before you can click other buttons. You can also turn off hideOnClickOutside and manually control whether the keyboard is displayed to achieve closing the keyboard when clicking outside, which is more flexible.

html
<wd-cell title="Two-way Binding" :value="value1" is-link @click="showKeyBoard" />
<wd-keyboard :modal="true" :hide-on-click-outside="true" v-model:visible="visible" @input="onInput" @delete="onDelete" />
ts
const { show: showToast } = useToast()
const visible = ref<boolean>(false)
const value1 = ref<string>('')

function showKeyBoard() {
  visible.value = true
}

const onInput = (value) => showToast(`${value}`)
const onDelete = () => showToast('Delete')

Attributes

ParameterDescriptionTypeDefault Value
v-model:visibleWhether expandedbooleanfalse
v-modelCurrent input valuestring''
titleKeyboard titlestring-
modeKeyboard mode, optional values are default, custom, carKeyboardModedefault
z-indexZ-indexnumber100
maxlengthMaximum input lengthnumberInfinity
show-delete-keyWhether to show delete key; only effective for default numeric keyboard and sidebar keyboardbooleantrue
random-key-orderWhether to randomly sort numeric keysbooleanfalse
close-textClose button text; displayed in header for default/license plate mode, displayed on right large button for custom modestring-
delete-textDelete button textstring-
close-button-loadingWhether close button shows loading statebooleanfalse
modalWhether to show mask; when set to false, mask is transparentbooleanfalse
hide-on-click-outsideWhether to allow closing keyboard by clicking outside, also controls whether to render maskbooleantrue
lock-scrollWhether to lock background scrollingbooleantrue
safe-area-inset-bottomWhether to adapt to bottom safe areabooleantrue
extra-keyExtra key, can pass single string or string array; custom mode supports two extra keysstring | string[]-
root-portal v1.11.0Whether to detach from page structure, used to solve fixed positioning issuesbooleanfalse
v-model:car-lang v1.13.0License plate keyboard language mode, effective when mode=car, optional values are zh, enCarKeyboardLang-
auto-switch-lang v1.13.0Whether to automatically switch license plate keyboard language, effective when mode=car and car-lang is in uncontrolled statebooleanfalse
custom-classCustom class name for root nodestring''
custom-styleCustom style for root nodestring''

Slots

NameDescription
titleCustom title content

Events

Event NameDescriptionParameters
inputTriggered when clicking an inputtable keykey: string
deleteTriggered when clicking delete key-
closeTriggered when clicking close button or mask to close-
update:visibleTriggered when keyboard visibility changesvisible: boolean
update:modelValueTriggered when current input value changesvalue: string
update:carLangTriggered when license plate keyboard language changeslang: 'zh' | 'en'

External Style Classes

Class NameDescription
custom-classRoot node style class
custom-styleRoot node style

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-keyboard-bg$filled-content键盘背景色
--wot-keyboard-color$text-main键盘文字颜色
--wot-keyboard-padding$padding-tight键盘内容间距
--wot-keyboard-header-height$n-40键盘头部高度
--wot-keyboard-title-color$text-secondary键盘标题颜色
--wot-keyboard-title-font-size$typography-body-size-main键盘标题字号
--wot-keyboard-close-color$primary-6关闭按钮文字颜色
--wot-keyboard-close-opacity-hover$opacity-dimmer关闭按钮悬浮透明度
--wot-keyboard-close-font-size$typography-body-size-main关闭按钮字号
--wot-keyboard-close-padding$padding-zero $padding-loose关闭按钮内边距

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.