UNPKG

11.3 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction, FormItemProps } from './common'
3interface InputProps extends StandardProps, FormItemProps {
4 /** 输入框的初始内容
5 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
6 */
7 value?: string
8 /** 设置 React 非受控输入框的初始内容
9 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
10 * @unique
11 */
12 defaultValue?: string
13 /** input 的类型
14 * @default "text"
15 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
16 */
17 type?: keyof InputProps.Type
18 /** 是否是密码类型
19 * @default false
20 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
21 */
22 password?: boolean
23 /** 输入框为空时占位符
24 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
25 */
26 placeholder?: string
27 /** 指定 placeholder 的样式
28 * @supported weapp, alipay, swan, tt, qq, jd, rn
29 */
30 placeholderStyle?: string
31 /** 指定 placeholder 的样式类
32 * @default "input-placeholder"
33 * @supported weapp, alipay, swan, tt, qq, jd
34 */
35 placeholderClass?: string
36 /** 指定 placeholder 的文本颜色
37 * @supported rn
38 */
39 placeholderTextColor?: string
40 /** 是否禁用
41 * @default false
42 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
43 */
44 disabled?: boolean
45 /** 最大输入长度,设置为 -1 的时候不限制最大长度
46 * @default 140
47 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
48 */
49 maxlength?: number
50 /** 指定光标与键盘的距离,单位 px 。取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离
51 * @default 0
52 * @supported weapp, swan, tt, qq, jd
53 */
54 cursorSpacing?: number
55 /** (即将废弃,请直接使用 focus )自动聚焦,拉起键盘
56 * @default false
57 * @deprecated
58 * @supported weapp, qq, jd, h5, harmony_hybrid
59 */
60 autoFocus?: boolean
61 /** 获取焦点
62 * @default false
63 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
64 */
65 focus?: boolean
66 /** 设置键盘右下角按钮的文字,仅在type='text'时生效
67 * @alipay confirm-type 与 enableNative 属性冲突,若希望 confirm-type 生效,enableNative 不能设定为 false,而且不能设定 always-system
68 * @default done
69 * @supported weapp, alipay, swan, tt, qq, jd, rn
70 */
71 confirmType?: keyof InputProps.ConfirmType
72 /** 点击键盘右下角按钮时是否保持键盘不收起
73 * @default false
74 * @supported weapp, alipay, swan, tt, qq, jd
75 */
76 confirmHold?: boolean
77 /** 指定focus时的光标位置
78 * @supported weapp, alipay, swan, tt, qq, jd, rn
79 */
80 cursor?: number
81 /** 光标起始位置,自动聚集时有效,需与selection-end搭配使用
82 * @default -1
83 * @supported weapp, alipay, swan, tt, qq, jd, rn
84 */
85 selectionStart?: number
86 /** 光标结束位置,自动聚集时有效,需与selection-start搭配使用
87 * @default -1
88 * @supported weapp, alipay, swan, tt, qq, jd, rn
89 */
90 selectionEnd?: number
91 /** 键盘弹起时,是否自动上推页面
92 * @default true
93 * @supported weapp, swan, tt, qq, jd
94 */
95 adjustPosition?: boolean
96 /** focus 时,点击页面的时候不收起键盘
97 * @default false
98 * @supported weapp, tt
99 */
100 holdKeyboard?: boolean
101 /**
102 * 强制 input 处于同层状态,默认 focus 时 input 会切到非同层状态 (仅在 iOS 下生效)
103 * @default false
104 * @supported weapp
105 */
106 alwaysEmbed?: boolean
107 /**
108 * 安全键盘加密公钥的路径,只支持包内路径
109 * @supported weapp
110 */
111 safePasswordCertPath?: string
112 /**
113 * 安全键盘输入密码长度
114 * @supported weapp
115 */
116 safePasswordLength?: number
117 /**
118 * 安全键盘加密时间戳
119 * @supported weapp
120 */
121 safePasswordTimeStamp?: number
122 /**
123 * 安全键盘加密盐值
124 * @supported weapp
125 */
126 safePasswordNonce?: string
127 /**
128 * 安全键盘计算hash盐值,若指定custom-hash 则无效
129 * @supported weapp
130 */
131 safePasswordSalt?: string
132 /**
133 * 安全键盘计算hash的算法表达式,如 `md5(sha1('foo' + sha256(sm3(password + 'bar'))))`
134 * @supported weapp
135 */
136 safePasswordCustomHash?: string
137 /**
138 * 当 type 为 number, digit, idcard 数字键盘是否随机排列
139 * @default false
140 * @supported alipay
141 */
142 randomNumber?: boolean
143 /**
144 * 是否为受控组件。为 true 时,value 内容会完全受 setData 控制。
145 *
146 * 建议当 type 值为 text 时不要将 controlled 设置为 true,详见 [Bugs & Tips](https://opendocs.alipay.com/mini/component/input#Bug%20%26%20Tip)
147 * @default false
148 * @supported alipay
149 */
150 controlled?: boolean
151 /** 用于透传 `WebComponents` 上的属性到内部 H5 标签上
152 * @supported h5, harmony_hybrid
153 */
154 nativeProps?: Record<string, unknown>
155 /** 组件名字,用于表单提交获取数据。
156 * @supported alipay
157 */
158 name?: string
159 /** 是否强制使用系统键盘和 Web-view 创建的 input 元素。为 true 时,confirm-type、confirm-hold 可能失效。
160 * @default false
161 * @supported alipay
162 */
163 alwaysSystem?: boolean
164 /** 无障碍访问,(属性)元素的额外描述
165 * @supported qq
166 */
167 ariaLabel?: string
168 /** 用于分发目的。取值:0 和 1,其中 0 表示默认,1 表示手机号,需要和留资分发配置一起使用,详情见留资分发配置。
169 * @supported tt
170 * @default 0
171 */
172 clueType?: number
173 /** 当键盘输入时,触发input事件,event.detail = {value, cursor, keyCode},处理函数可以直接 return 一个字符串,将替换输入框的内容。
174 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
175 */
176 onInput?: CommonEventFunction<InputProps.inputEventDetail>
177 /** 输入框聚焦时触发,event.detail = { value, height },height 为键盘高度
178 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
179 */
180 onFocus?: CommonEventFunction<InputProps.inputForceEventDetail>
181 /** 输入框失去焦点时触发
182 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
183 */
184 onBlur?: CommonEventFunction<InputProps.inputValueEventDetail>
185 /** 点击完成按钮时触发
186 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
187 */
188 onConfirm?: CommonEventFunction<InputProps.inputValueEventDetail>
189 /** 键盘高度发生变化的时候触发此事件
190 * @supported weapp, tt, qq
191 */
192 onKeyboardHeightChange?: CommonEventFunction<InputProps.onKeyboardHeightChangeEventDetail>
193 /** 用户昵称审核完毕后触发,仅在 type 为 "nickname" 时有效,event.detail = { pass, timeout }
194 * @supported weapp
195 */
196 onNickNameReview?: CommonEventFunction
197}
198declare namespace InputProps {
199 /** Input 类型 */
200 interface Type {
201 /** 文本输入键盘
202 * @supported weapp, alipay, h5, rn, harmony_hybrid
203 */
204 text
205 /** 数字输入键盘
206 * @supported weapp, alipay, h5, rn, harmony_hybrid
207 */
208 number
209 /** 身份证输入键盘
210 *@supported weapp, alipay, rn
211 */
212 idcard
213 /** 带小数点的数字键盘
214 * @supported weapp, alipay, h5, rn, harmony_hybrid
215 */
216 digit
217 /** 密码安全输入键盘[指引](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/safe-password.html)
218 * @supported weapp, alipay
219 */
220 'safe-password'
221 /** 昵称输入键盘
222 * @supported weapp, alipay
223 */
224 nickname
225 /** 数字输入键盘
226 * @supported alipay
227 */
228 numberpad
229 /** 带小数点的数字键盘
230 * @supported alipay
231 */
232 digitpad
233 /** 身份证输入键盘
234 * @supported alipay
235 */
236 idcardpad
237 }
238 /** Confirm 类型 */
239 interface ConfirmType {
240 /** 右下角按钮为“发送” */
241 send
242 /** 右下角按钮为“搜索” */
243 search
244 /** 右下角按钮为“下一个” */
245 next
246 /** 右下角按钮为“前往” */
247 go
248 /** 右下角按钮为“完成” */
249 done
250 }
251 /** > 注意:React-Native 端 `inputEventDetail` 仅实现参数 `value`,若需实时获取光标位置则可通过 [`onSelectionChange`](https://reactnative.dev/docs/textinput#onselectionchange) 实现。 */
252 interface inputEventDetail {
253 /** 输入值 */
254 value: string
255 /** 光标位置 */
256 cursor: number
257 /** 键值 */
258 keyCode: number
259 }
260 interface inputForceEventDetail {
261 /** 输入值 */
262 value: string
263 /** 键盘高度 */
264 height: number
265 }
266 interface inputValueEventDetail {
267 /** 输入值 */
268 value: string
269 }
270 interface onKeyboardHeightChangeEventDetail {
271 /** 键盘高度 */
272 height: number
273 /** 持续时间 */
274 duration: number
275 }
276}
277/** 输入框。该组件是原生组件,使用时请注意相关限制
278 * @classification forms
279 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony, harmony_hybrid
280 * @example_react
281 * ```tsx
282 * class App extends Component {
283 * render () {
284 * return (
285 * <View className='example-body'>
286 * <Text>可以自动聚焦的 input</Text>
287 * <Input type='text' placeholder='将会获取焦点' focus/>
288 * <Text>控制最大输入长度的 input</Text>
289 * <Input type='text' placeholder='最大输入长度为 10' maxLength='10'/>
290 * <Text>数字输入的 input</Text>
291 * <Input type='number' placeholder='这是一个数字输入框'/>
292 * <Text>密码输入的 input</Text>
293 * <Input type='password' password placeholder='这是一个密码输入框'/>
294 * <Text>带小数点的 input</Text>
295 * <Input type='digit' placeholder='带小数点的数字键盘'/>
296 * <Text>身份证输入的 input</Text>
297 * <Input type='idcard' placeholder='身份证输入键盘'/>
298 * <Text>控制占位符颜色的 input</Text>
299 * <Input type='text' placeholder='占位符字体是红色的' placeholderStyle='color:red'/>
300 * </View>
301 * )
302 * }
303 * }
304 * ```
305 * @example_vue
306 * ```html
307 * <template>
308 * <view class="example-body">
309 * <text>可以自动聚焦的 input</text>
310 * <input type="text" placeholder="将会获取焦点" :focus="true" />
311 * <text>控制最大输入长度的 input</text>
312 * <input type="text" placeholder="最大输入长度为 10" maxLength="10"/>
313 * <text>数字输入的 input</text>
314 * <input type="number" placeholder="这是一个数字输入框"/>
315 * <text>密码输入的 input</text>
316 * <input type="password" :password="true" placeholder="这是一个密码输入框"/>
317 * <text>带小数点的 input</text>
318 * <input type="digit" placeholder="带小数点的数字键盘"/>
319 * <text>身份证输入的 input</text>
320 * <input type="idcard" placeholder="身份证输入键盘"/>
321 * <text>控制占位符颜色的 input</text>
322 * <input type="text" placeholder="占位符字体是红色的" placeholder-style="color:red;"/>
323 * </view>
324 * </template>
325 * ```
326 * @see https://developers.weixin.qq.com/miniprogram/dev/component/input.html
327 */
328declare const Input: ComponentType<InputProps>
329export { Input, InputProps }