Skip to main content

input

Props

PropertyTypeDefault ValueRequiredDescription
valueString, NumberThe initial content in the input box.
typeStringtextThe type of input.
passwordBooleanfalseSpecifies whether the input is password-type content.
placeholderStringThe placeholder used when the input box is empty.
placeholderStyleStringSpecifies the style of the placeholder.
placeholderClassStringinput-placeholderSpecifies the style class of the placeholder.
disabledBooleanfalseSpecifies whether to disable the component.
maxlengthNumber140The maximum length. When it is set to -1, the maximum length is not limited.
cursorSpacingNumber0Specifies the distance between the cursor and the keyboard. It is either the distance between the input box and the bottom of the screen or the distance specified via cursorSpacing, whichever is smaller..
autoFocusBooleanfalse(Will be discarded soon. Use the focus instead.) Auto focus. The keyboard is automatically displayed.
focusBooleanfalseGets focus.
confirmTypeStringdoneSets the text on the lower-right button on the keyboard. It takes effect only when type='text'.
confirmHoldBooleanfalseSpecifies whether the keyboard is not hidden when the lower-right button on the keyboard is tapped.
cursorNumberSpecifies the cursor position during focusing.
selectionStartNumber-1The start position of the cursor. It takes effect only during auto focusing, and needs to used with selection-end.
selectionEndNumber-1The end position of the cursor. It takes effect only during auto focusing, and needs to used with selection-start.
adjustPositionBooleantrueSpecifies whether to automatically push up the page when the keyboard is displayed.
holdKeyboardBooleanfalseSpecifies whether to hide the keyboard when clicking page while the input is focused.
onInputEvent handlerTriggered when the user taps the keyboard. event.detail = { value, cursor, keyCode }, where keyCode is the key value.box.
onFocusEvent handlerTriggered when the input box is focused. event.detail = { value, height }, where height is the height of the keyboard.
onBlurEvent handlerTriggered when the input box is unfocused. event.detail = { value }.
onConfirmEvent handlerTriggered when the Done button is tapped. event.detail = { value }.
onKeyboardHeightChangeEvent handlerTriggered when the height of the keyboard changes. event.detail = { height, duration}.
autoFillString'username', 'password', 'newPassword', 'oneTime2FA', 'oneTimeEmail', 'oneTimeSMS', 'none'
showConfirmBarBooleanfalseSpecifies whether to display the bar containing the Done button above the keyboard.

Valid values of type

ValueDescription
textKeyboard for text input.
numberKeyboard for number input.
digitNumeric keypad with decimal point.

Valid values of confirm-type

ValueDescription
sendIndicates that the button in the lower right corner is Send.
searchIndicates that the button in the lower right corner is Search.
nextIndicates that the button in the lower right corner is Next.
goIndicates that the button in the lower right corner is GO.
doneIndicates that the button in the lower right corner is Done.
ValueDescription
shareTrigger the user to share.

Example

js

Page({
data: {
inputValue: ''
},
bindKeyInput: function (e) {
this.setData({
inputValue: e.detail.value
})
}
})

bxml

<theme-context>
<view class='container'>
<view>Auto focus input</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input auto-focus placeholder="Auto focus"/>
</view>
</view>
</view>

<view>The maximum length input</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input maxlength="10" placeholder="The maximum length is 10" />
</view>
</view>
</view>

<view>get input value:{{inputValue}}</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input maxlength="10" bindinput="bindKeyInput" placeholder="please input the value"/>
</view>
</view>
</view>

<view>number input</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input type="number" placeholder="number input" />
</view>
</view>
</view>

<view>password input</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input type="password" placeholder="password input" />
</view>
</view>
</view>

<view>digit input</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input type="digit" placeholder="digit input"/>
</view>
</view>
</view>

<view>An input that controls the color of the placeholder</view>
<view class='bnui-cells bnui-cells_after-title'>
<view class='bnui-cell bnui-cell_input'>
<view class='bnui-cell__bd'>
<input placeholder-style="color:#F76260" placeholder="placeholder font is red" />
</view>
</view>
</view>

</view>
</theme-context>

Tip

if developer need change the caret-color of input component, developer should use css class to set it instead of inline style