# input
基礎(chǔ)庫(kù) 1.0.0 開始支持,低版本需做兼容處理。
微信 Windows 版:支持
微信 Mac 版:支持
微信 鴻蒙 OS 版:支持
渲染框架支持情況:Skyline (使用最新 Nightly 工具調(diào)試)、WebView
# 功能描述
輸入框。該組件是原生組件,使用時(shí)請(qǐng)注意相關(guān)限制
# 通用屬性
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 | 最低版本 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| value | string | 是 | 輸入框的初始內(nèi)容 | 1.0.0 | |||||||||||||||||||||||
| type | string | text | 否 | input 的類型 | 1.0.0 | ||||||||||||||||||||||
| |||||||||||||||||||||||||||
| password | boolean | false | 否 | 是否是密碼類型 | 1.0.0 | ||||||||||||||||||||||
| placeholder | string | 是 | 輸入框?yàn)榭諘r(shí)占位符 | 1.0.0 | |||||||||||||||||||||||
| placeholder-style | string | 是 | 指定 placeholder 的樣式 | 1.0.0 | |||||||||||||||||||||||
| disabled | boolean | false | 否 | 是否禁用 | 1.0.0 | ||||||||||||||||||||||
| maxlength | number | 140 | 否 | 最大輸入長(zhǎng)度,設(shè)置為 -1 的時(shí)候不限制最大長(zhǎng)度 | 1.0.0 | ||||||||||||||||||||||
| cursor-spacing | number | 0 | 否 | 指定光標(biāo)與鍵盤的距離,取 input 距離底部的距離和 cursor-spacing 指定的距離的最小值作為光標(biāo)與鍵盤的距離 | 1.0.0 | ||||||||||||||||||||||
| auto-focus | boolean | false | 否 | (即將廢棄,請(qǐng)直接使用 focus )自動(dòng)聚焦,拉起鍵盤 | 1.0.0 | ||||||||||||||||||||||
| focus | boolean | false | 否 | 獲取焦點(diǎn) | 1.0.0 | ||||||||||||||||||||||
| confirm-type | string | done | 否 | 設(shè)置鍵盤右下角按鈕的文字,僅在type='text'時(shí)生效 | 1.1.0 | ||||||||||||||||||||||
| |||||||||||||||||||||||||||
| always-embed | boolean | false | 否 | 強(qiáng)制 input 處于同層狀態(tài),默認(rèn) focus 時(shí) input 會(huì)切到非同層狀態(tài) (僅在 iOS 下生效) | 2.10.4 | ||||||||||||||||||||||
| confirm-hold | boolean | false | 否 | 點(diǎn)擊鍵盤右下角按鈕時(shí)是否保持鍵盤不收起 | 1.1.0 | ||||||||||||||||||||||
| cursor | number | 是 | 指定focus時(shí)的光標(biāo)位置 | 1.5.0 | |||||||||||||||||||||||
| cursor-color | string | 是 | 光標(biāo)顏色。iOS 下的格式為十六進(jìn)制顏色值 #000000,安卓下的只支持 default 和 green,Skyline 下無限制 | 3.1.0 | |||||||||||||||||||||||
| selection-start | number | -1 | 否 | 光標(biāo)起始位置,自動(dòng)聚集時(shí)有效,需與selection-end搭配使用 | 1.9.0 | ||||||||||||||||||||||
| selection-end | number | -1 | 否 | 光標(biāo)結(jié)束位置,自動(dòng)聚集時(shí)有效,需與selection-start搭配使用 | 1.9.0 | ||||||||||||||||||||||
| adjust-position | boolean | true | 否 | 鍵盤彈起時(shí),是否自動(dòng)上推頁面 | 1.9.90 | ||||||||||||||||||||||
| hold-keyboard | boolean | false | 否 | focus時(shí),點(diǎn)擊頁面的時(shí)候不收起鍵盤 | 2.8.2 | ||||||||||||||||||||||
| safe-password-cert-path | string | 否 | 安全鍵盤加密公鑰的路徑,只支持包內(nèi)路徑。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| safe-password-length | number | 否 | 安全鍵盤輸入密碼長(zhǎng)度。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| safe-password-time-stamp | number | 否 | 安全鍵盤加密時(shí)間戳。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| safe-password-nonce | string | 否 | 安全鍵盤加密鹽值。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| safe-password-salt | string | 否 | 安全鍵盤計(jì)算hash鹽值,若指定custom-hash 則無效。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| safe-password-custom-hash | string | 否 | 安全鍵盤計(jì)算hash的算法表達(dá)式,如 md5(sha1('foo' + sha256(sm3(password + 'bar'))))。鴻蒙 OS 暫不支持 | 2.18.0 | |||||||||||||||||||||||
| bindinput | eventhandle | 是 | 鍵盤輸入時(shí)或內(nèi)容改變時(shí)觸發(fā)。event.detail = { value: string, cursor?: number, keyCode?: number },cursor 為光標(biāo)位置,keyCode 為鍵值。2.1.0 起支持,處理函數(shù)可以直接 return 一個(gè)字符串,將替換輸入框的內(nèi)容。 | 1.0.0 | |||||||||||||||||||||||
| bindchange | eventhandle | 是 | 鍵盤非聚焦?fàn)顟B(tài)內(nèi)容改變時(shí)觸發(fā)。event.detail = { value: string } | 1.0.0 | |||||||||||||||||||||||
| bindfocus | eventhandle | 是 | 輸入框聚焦時(shí)觸發(fā),event.detail = { value: string, height: number },height 為鍵盤高度,在基礎(chǔ)庫(kù) 1.9.90 起支持 | 1.0.0 | |||||||||||||||||||||||
| bindblur | eventhandle | 是 | 輸入框失去焦點(diǎn)時(shí)觸發(fā),event.detail = { value: string, encryptedValue?: string, encryptError?: string } | 1.0.0 | |||||||||||||||||||||||
| bindconfirm | eventhandle | 是 | 點(diǎn)擊完成按鈕時(shí)觸發(fā),event.detail = { value: string, encryptedValue?: string, encryptError?: string } | 1.0.0 | |||||||||||||||||||||||
| bindkeyboardheightchange | eventhandle | 是 | 鍵盤高度發(fā)生變化的時(shí)候觸發(fā)此事件,event.detail = {height: number, duration: number} | 2.7.0 | |||||||||||||||||||||||
| bindnicknamereview | eventhandle | 是 | 用戶昵稱審核完畢后觸發(fā),僅在 type 為 "nickname" 時(shí)有效,event.detail = { pass: boolean, timeout: boolean } | 2.29.1 | |||||||||||||||||||||||
# Skyline 特有屬性
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 | 最低版本 | |
|---|---|---|---|---|---|---|
| bind:selectionchange | eventhandle | 否 | 選區(qū)改變事件, {selectionStart, selectionEnd} | 3.2.0 | ||
| bind:keyboardcompositionstart | eventhandle | 否 | 輸入法開始新的輸入時(shí)觸發(fā) (僅當(dāng)輸入法支持時(shí)觸發(fā)) | 3.2.0 | ||
| bind:keyboardcompositionupdate | eventhandle | 否 | 輸入法輸入字符時(shí)觸發(fā)(僅當(dāng)輸入法支持時(shí)觸發(fā)) | 3.2.0 | ||
| bind:keyboardcompositionend | eventhandle | 否 | 輸入法輸入結(jié)束時(shí)觸發(fā)(僅當(dāng)輸入法支持時(shí)觸發(fā)) | 3.2.0 | ||
| worklet:onkeyboardheightchange | worklet | 否 | 鍵盤高度變化時(shí)觸發(fā)。event.detail = {height: height, pageBottomPadding: pageBottomPadding}; height: 鍵盤高度,pageBottomPadding: 頁面上推高度 | 3.2.4 |
# WebView 特有屬性
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 | 最低版本 | |
|---|---|---|---|---|---|---|
| placeholder-class | string | input-placeholder | 否 | 指定 placeholder 的樣式類 | 1.0.0 |
# Bug & Tip
tip: confirm-type的最終表現(xiàn)與手機(jī)輸入法本身的實(shí)現(xiàn)有關(guān),部分安卓系統(tǒng)輸入法和第三方輸入法可能不支持或不完全支持tip: input 組件是一個(gè)原生組件,字體是系統(tǒng)字體,所以無法設(shè)置 font-familytip: 在 input 聚焦期間,避免使用 css 動(dòng)畫tip: 對(duì)于將input封裝在自定義組件中、而form在自定義組件外的情況,form將不能獲得這個(gè)自定義組件中input的值。此時(shí)需要使用自定義組件的 內(nèi)置 behaviorswx://form-fieldtip: 鍵盤高度發(fā)生變化,keyboardheightchange事件可能會(huì)多次觸發(fā),開發(fā)者對(duì)于相同的height值應(yīng)該忽略掉bug: 微信版本6.3.30, focus 屬性設(shè)置無效bug: 微信版本6.3.30, placeholder 在聚焦時(shí)出現(xiàn)重影問題