JGuang

数字键盘 <Experimental></Experimental>

NumberKeyboard <Experimental></Experimental> · Ant Design Mobile

交互预览
npm install antd-mobile@5.43.0

数字键盘 <Experimental></Experimental> NumberKeyboard <Experimental></Experimental>

数字键盘面板。

安装

npm install antd-mobile@5.43.0

antd-mobile 是移动网页组件库,不是 React Native 或小程序组件。React 19 项目需在入口用 unstableSetRender 注册 createRoot,否则 Toast、Dialog 等命令式 API 无法渲染;深色模式通过 <html data-prefers-color-scheme="dark"> 切换。

示例来自 Ant Design Mobile 官方仓库(MIT),固定在 npm 5.43.0 对应的提交;示例中的 DemoBlock 等展示辅助组件由 JGuang 重写,不属于 antd-mobile 的 API。

数字键盘面板。

何时使用

适用于输入数字内容时。

可以配合密码输入框组件或自定义的输入框组件使用。

如果情况允许的话,我们更推荐使用系统或客户端提供的原生键盘。虚拟数字键盘只是一些特殊的场景下的补充。

示例

tips: 仅移动端下删除按钮支持长按快删(通过 touchStart/touchEnd 实现)。

NumberKeyboard

属性

属性说明类型默认值
afterClose键盘完全收起回调() => void-
afterShow键盘完全弹出回调() => void-
closeOnConfirm是否在点击确定按钮时自动关闭booleantrue
confirmText完成按钮文案,null 不展示string | nullnull
customKey自定义按钮string | { key: string; title: string } | (string | { key: string; title: string })[]-
destroyOnClose不可见时是否销毁 DOM 结构booleanfalse
forceRender强制渲染内容booleanfalse
getContainer指定挂载的 HTML 节点,默认为 body,如果为 null 的话,会渲染到当前节点HTMLElement | () => HTMLElement | null() => document.body
onClose点击关闭时触发() => void-
onConfirm点击确定按钮时触发() => void-
onDelete删除内容回调() => void-
onInput输入内容回调(v: string) => void-
randomOrder是否乱序键盘booleanfalse
safeArea是否开启安全区适配booleantrue
showCloseButton是否展示收起键盘箭头booleantrue
title键盘标题string-
visible是否展示boolean-

此外还支持 Popup 的以下属性: stopPropagation

FAQ

数字键盘是否支持自动从短信中读取验证码?

不支持。

数字键盘与 VirtualInput 如何搭配使用?

参考 VirtualInput