NumberKeyboard
Numeric input panel with application-owned values, controlled editing, randomized keys and confirmation guards.
Import
Use <hui-number-keyboard> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-input
custom-class="hui-space__item"
:model-value="value"
readonly
placeholder="点下方按钮 / Open below"
/>
<hui-button custom-class="hui-space__item" @click="visible = true"
>打开数字键盘 / Open keyboard</hui-button
>
<hui-number-keyboard
v-model:visible="visible"
v-model="value"
custom-class="hui-space__item"
theme="custom"
:maxlength="6"
:extra-key="['.', '00']"
confirm-text="完成 / Done"
@input="(key) => (lastEvent = key)"
@delete="lastEvent = 'delete'"
@confirm="(value) => (lastEvent = 'confirm:' + String(value))"
@close="(reason) => (lastEvent = 'close:' + reason)"
/>
<text class="hui-space__item">{{ value }} / {{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const visible = ref(false)
const value = ref('')
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
visible | boolean | undefined | Controlled visibility. |
defaultVisible | boolean | false | Initial uncontrolled visibility. |
modelValue | string | — | Controlled current value; accept update:modelValue to change it. |
maxlength | number | Infinity | Maximum controlled input length; omitted means unlimited. |
theme | NumberKeyboardTheme | 'default' | Default keypad or custom keypad with a side confirm key. |
extraKey | string | string[] | '' | One extra key, or up to two in custom mode. |
title | string | — | Heading text, or the title-placeholder switch for Skeleton. |
closeText | string | — | Header close label; empty text hides it. |
confirmText | string | — | Confirm-key label. |
showDeleteKey | boolean | true | Displays the delete key. |
randomKeyOrder | boolean | false | Shuffles digits each time the keyboard opens. |
closeOnClickOutside | boolean | true | Uses a transparent backdrop; touching it requests close. |
beforeConfirm | (value: string | undefined) => boolean | void | Promise<boolean | void> | — | Asynchronous confirmation guard. |
safeAreaInsetBottom | boolean | true | Adds bottom safe-area padding. |
vibrate | boolean | false | Requests brief haptic feedback. |
zIndex | number | — | Explicit stacking level. |
rootPortal | boolean | false | Uses a root portal on supported mini-program targets. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
update:modelValue | (value: string) |
input | (key: string) |
delete | () |
confirm | (value: string | undefined) |
update:visible | (visible: boolean) |
close | (reason: NumberKeyboardCloseReason) |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
title | — |
delete | — |
extra-key | { keyValue } |
Methods
None.
Types
NumberKeyboardTheme、NumberKeyboardCloseReason、NumberKeyboardProps、NumberKeyboardEmits.
Platform notes
A transparent backdrop is used consistently above the keyboard; switching inputs may require closing it first. Holding delete repeats every 80 ms and suppresses the trailing click. Without modelValue, only input/delete events are emitted; applications own amount and decimal rules.
Device smoke checklist.