Skip to content

PasswordInput Password Input ​

A grid-based password input component, suitable for payment passwords, SMS verification codes, and other scenarios. Usually used in conjunction with the Keyboard component.

wd-password-input is only responsible for displaying input values, cursor, and prompt information, and does not directly handle input logic. Usually focused is bound to the keyboard visibility state, and the keyboard is opened in the focus event.

Component Type ​

Basic Usage ​

Use with wd-keyboard component to achieve password input.

html
<wd-password-input v-model="value" :focused="showKeyboard" @focus="showKeyboard = true" />
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="6" />
typescript
import { ref } from 'vue'

const value = ref<string>('123')
const showKeyboard = ref<boolean>(false)

Component Variants ​

Custom Length ​

Set password digits via length, and synchronize setting keyboard's maxlength.

html
<wd-password-input v-model="value" :length="4" :focused="showKeyboard" @focus="showKeyboard = true" />
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="4" />

Component Style ​

Grid Spacing ​

Set spacing between grids via gutter, default unit is px.

html
<wd-password-input v-model="value" :gutter="10" :focused="showKeyboard" @focus="showKeyboard = true" />
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="6" />

Content Form ​

Plain Text Display ​

Set mask to false to display input content in plain text, suitable for SMS verification codes and other scenarios.

html
<wd-password-input v-model="value" :mask="false" :focused="showKeyboard" @focus="showKeyboard = true" />
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="6" />

Prompt Information ​

Set normal prompt information via info, and error prompts via error-info.

html
<wd-password-input
  v-model="value"
  info="Password is 6 digits"
  :error-info="errorInfo"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="6" />
typescript
import { ref, watch } from 'vue'

const value = ref('123')
const errorInfo = ref('')
const showKeyboard = ref(false)

watch(value, (newVal) => {
  if (newVal.length === 6 && newVal !== '123456') {
    errorInfo.value = 'Password error'
  } else {
    errorInfo.value = ''
  }
})

Special Usage ​

Random Keyboard ​

Combined with wd-keyboard's random-key-order capability, security in numeric input scenarios can be enhanced.

html
<wd-password-input v-model="value" :focused="showKeyboard" @focus="showKeyboard = true" />
<wd-keyboard v-model="value" v-model:visible="showKeyboard" :maxlength="6" random-key-order />

Attributes ​

ParameterDescriptionTypeDefault Value
v-modelCurrent input valuestring''
maskWhether to hide password contentbooleantrue
infoText prompt below input boxstring''
error-infoError prompt below input boxstring''
gutterSpacing between input box grids, default unit is pxnumber | string0
lengthPassword lengthnumber6
focusedWhether in focused state; cursor is displayed when focused, usually linked with keyboard visibility statebooleantrue
custom-classCustom class name for root nodestring''
custom-styleCustom style for root nodestring''

Events ​

Event NameDescriptionParameters
focusTriggered when clicking password input boxevent: Event

External Style Classes ​

Class NameDescription
custom-classRoot node style

主题定制 ​

CSS 变量 ​

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

名称默认值描述
--wot-password-input-height$n-50输入区域高度
--wot-password-input-margin$n-16组件外边距
--wot-password-input-font-size$typography-title-size-large输入字号
--wot-password-input-line-height$typography-title-line-height-size-large输入行高
--wot-password-input-radius$n-6输入格圆角
--wot-password-input-bg$filled-oppo输入格背景色
--wot-password-input-info-color$text-auxiliary提示信息颜色
--wot-password-input-info-font-size$typography-body-size-main提示信息字号
--wot-password-input-border-color$border-main边框颜色
--wot-password-input-border-width$stroke-main边框宽度
--wot-password-input-error-info-color$danger-main错误提示颜色
--wot-password-input-dot-size$n-10密码点尺寸
--wot-password-input-dot-color$text-main密码点颜色
--wot-password-input-dot-radius$radius-full密码点圆角
--wot-password-input-text-color$text-main输入文本颜色
--wot-password-input-cursor-color$text-main光标颜色
--wot-password-input-cursor-width$n-1光标宽度
--wot-password-input-cursor-height40%光标高度
--wot-password-input-cursor-duration1s光标闪烁周期

Source Code ​

Documentation
• Component

Released under the MIT License.

Released under the MIT License.