NumberKeyboard
introduce
The virtual numeric keyboard can be used with Password Input Box Component or a custom input box component.
Code Demo
Default style
The numeric keyboard provides input
, delete
, and blur
events, which respectively correspond to the actions of inputting content, deleting content, and losing focus.
<z-cell title="Pop up default keyboard" is-link @click="show = true" />
<z-number-keyboard
:show="show"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
import { ref } from 'vue';
import { useToast } from '../../uni_modules/zebra-ui'
const toast = useToast()
const show = ref(false)
const onInput = (value: string) => toast.showToast(value)
const onDelete = () => toast.showToast('Delete')
Keyboard with right sidebar
Set the theme attribute to custom
to display the right column of the keyboard, which is often used for inputting amounts.
<z-number-keyboard
:show="show"
theme="custom"
extra-key="."
close-button-text="Complete"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
ID number keyboard
The content of the key in the lower left corner can be set through the extra-key
attribute. For example, when you need to enter an ID number, you can set extra-key
to X
.
<z-cell plain type="primary" @touchstart.stop="show = true">
Pop up ID number keyboard
</z-cell>
<z-number-keyboard
:show="show"
extra-key="X"
close-button-text="Complete"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
Keyboard title
The keyboard title can be set via the title
attribute.
<z-cell plain type="primary" @touchstart.stop="show = true">
Pop up keyboard with title
</z-cell>
<z-number-keyboard
:show="show"
title="Keyboard title"
extra-key="."
close-button-text="Complete"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
Configure multiple buttons
When theme is custom
, it supports configuring two extra-key
in the form of array.
<z-cell plain type="primary" @touchstart.stop="show = true">
Pop up a keyboard configured with multiple keys
</z-cell>
<z-number-keyboard
:show="show"
theme="custom"
:extra-key="['00', '.']"
close-button-text="Complete"
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
Random number keyboard
The numeric keyboard can be randomly ordered through the random-key-order
attribute, which is often used in scenarios with high security levels.
<z-cell @touchstart.stop="show = true"> Pop up a keyboard with random numbers </z-cell>
<z-number-keyboard
:show="show"
random-key-order
@blur="show = false"
@input="onInput"
@delete="onDelete"
/>
Two-way binding
You can bind the current input value of the keyboard through v-model
and limit the input length through the maxlength
attribute.
<z-field
v-model="valueModel"
label="two-way binding"
readonly
clickable
@click="showValue = true"
/>
<z-number-keyboard
v-model="valueModel"
:show="showValue"
:maxlength="6"
@blur="showValue = false"
/>
import { ref } from 'vue';
const show = ref(true);
const value = ref('');
API
Props
Parameters | Description | Type | Default value |
---|---|---|---|
v-model | Current input value | string | - |
show | Whether to display the keyboard | boolean | - |
title | keyboard title | string | - |
theme | Style, optional value is custom | string | default |
maxlength | Maximum length of input value | number | string | Infinity |
transition | whether to enable cutscenes | boolean | true |
z-index | keyboard z-index level | number | string | 100 |
extra-key | The content of the extra key at the bottom | string | string | '' |
close-button-text | Close button text, not displayed if empty | string | - |
delete-button-text | Delete button text, if empty, the delete icon will be displayed | string | - |
close-button-loading | Whether to set the close button to loading state, only valid when theme="custom" | boolean | false |
show-delete-key | Whether to display the delete icon | boolean | true |
blur-on-close | Whether to trigger the blur event when the close button is clicked | boolean | true |
hide-on-click-outside | Whether to hide the keyboard when clicking outside | boolean | true |
safe-area-inset-bottom | Whether to enable Bottom Safe Area Adaptation | boolean | true |
random-key-order | Whether keys will be displayed in random order | boolean | false |
Events
Event name | Description | Callback parameters |
---|---|---|
input | Triggered when a key is clicked | key: string |
delete | Triggered when the delete key is clicked | - |
close | Triggered when the close button is clicked | - |
blur | Triggered when the close button or non-keyboard area is clicked | - |
show | Triggered when the keyboard is fully ejected | - |
hide | Triggered when the keyboard is fully retracted | - |
Slots
Name | Description |
---|---|
delete | Customize delete key content |
extra-key | Customize the button content in the lower left corner |
title-left | Customize the content on the left side of the title bar |
Theme customization
Style variables
The component provides the following CSS variables, which can be used to customize styles. For usage, please refer to ConfigProvider component.
Name | Default | Description |
---|---|---|
--z-number-keyboard-background | var(--z-gray-2) | - |
--z-number-keyboard-key-height | 96rpx | - |
--z-number-keyboard-key-font-size | 56rpx | - |
--z-number-keyboard-key-active-color | var(--z-gray-3) | - |
--z-number-keyboard-key-background | var(--z-white) | - |
--z-number-keyboard-delete-font-size | var(--z-font-size-lg) | - |
--z-number-keyboard-title-color | var(--z-gray-7) | - |
--z-number-keyboard-title-height | 68px | - |
--z-number-keyboard-title-font-size | var(--z-font-size-lg) | - |
--z-number-keyboard-close-padding | 0 var(--z-padding-md) | - |
--z-number-keyboard-close-color | var(--z-primary-color) | - |
--z-number-keyboard-close-font-size | var(--z-font-size-md) | - |
--z-number-keyboard-button-text-color | var(--z-white) | - |
--z-number-keyboard-button-background | var(--z-primary-color) | - |
--z-number-keyboard-z-index | 100 | - |