UNPKG

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