mCloud Design Mobile

mCloud Design Mobile

  • Docs
  • API
  • Help
  • Blog

›Component

Component

  • Button
  • SegmentedControl
  • SearchBar
  • Radio
  • Checkbox
  • Badge
  • Marquee
  • Switch
  • InputItem
  • NoticeBar
  • Textarea
  • List
  • Card
  • Picker
  • Label
  • EmptyView
  • Stepper
  • Tabs
  • DatePicker
  • Modal
  • Avatar
  • ActionSheet
  • ShareSheet

First Category

  • Button
  • Fifth Document

InputItem

单行文本输入

Basic Example

import React, { useState } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { InputItem } from 'mcloud-mobile'

export default () => {
    const [value, onChange] = useState('')
    const [title, onTitleChange] = useState('打卡助手')
    const [bankcard, bankcardChange] = useState('')
    const [phone, phoneChange] = useState('')
    const [password, passwordChange] = useState('')
    const [number, numberChange] = useState('')
    const [leftValue, leftValueChange] = useState('')
    return (
        <View style={styles.wrap}>
            <Text style={styles.boldTitle}>
                InputItem
            </Text>
            <Text style={styles.title}>
                默认
            </Text>
            <InputItem
                value={value}
                onChange={(text) => {
                    onChange(text)
                }}
                placeholder="请输入标题"
            >
                标题
            </InputItem>
            <InputItem
                value={title}
                onChange={(text) => {
                    onTitleChange(text)
                }}
                placeholder="请输入标题"
            >
                标题
            </InputItem>
            <Text style={styles.title}>
                格式
            </Text>
            <InputItem
                type="bankCard"
                value={bankcard}
                onChange={(text) => {
                    bankcardChange(text)
                }}
                placeholder="bankCard"
            >
                银行卡
            </InputItem>
            <InputItem
                type="phone"
                value={phone}
                onChange={(text) => {
                    phoneChange(text)
                }}
                placeholder="phone"
            >
                手机号
            </InputItem>
            <InputItem
                type="password"
                value={password}
                onChange={(text) => {
                    passwordChange(text)
                }}
                placeholder="password"
            >
                密码
            </InputItem>
            <InputItem
                type="number"
                value={number}
                onChange={(text) => {
                    numberChange(text)
                }}
                placeholder="number"
            >
                数字
            </InputItem>
            <Text style={styles.title}>
                输入内容在左侧的显示效果
            </Text>
            <InputItem
                clear
                textAlign="left"
                placeholder="请输入内容"
                value={leftValue}
                onChange={(text) => {
                    leftValueChange(text)
                }}
            />
        </View>
    )
}

const styles = StyleSheet.create({
    wrap: {
        flex: 1,
        backgroundColor: '#E6E6E6',
    },
    title: {
        fontSize: 14,
        color: '#1F2530',
        paddingVertical: 10,
        paddingLeft: 15,
    },
    boldTitle: {
        fontSize: 16,
        color: '#1F2530',
        paddingVertical: 10,
        paddingLeft: 10,
        fontWeight: '500',
    },
})

Props

属性说明类型默认值
type可以是银行卡bankCard; 手机号phone(此时最大长度固定为11,maxLength设置无效); 密码password; 数字number(为了尽量唤起带小数点的数字键盘,此类型并不是原生 number,而是<input type="text" pattern="[0-9]*" />); digit(表示原生的 number 类型); 以及其他标准 input type 类型Stringtext
valuevalue 值(受控与否参考https://facebook.github.io/react/docs/forms.html)String无
defaultValue设置初始默认值String-
placeholderplaceholderString''
placeholderTextColorplaceholderTextColorStringtheme.color_text_placeholder
editable是否可编辑booltrue
disabled是否禁用booltrue
autoFocus是否禁用booltrue
clear是否带清除功能(仅editable为true,disabled为false才生效)。在 Android 中, 处于编辑状态(focus)时 icon 才会出现, 且此组件被ScrollView包裹时, 设置ScrollView的keyboardShouldPersistTaps属性为handled或always时, icon才会正确响应点击事件boolfalse
maxLength最大长度number无
textAlign输入框的位置,可选值有 left 和 rightstringright
onChangechange 事件触发的回调函数(val: string): void-
onBlurblur 事件触发的回调函数(val: string): void-
onFocusfocus 事件触发的回调函数(val: string): void-
labelNumber标签的文字个数,可用2-7之间的数字number5
last如果是最后一项,则将移除borderBottom(默认拥有borderBottom)boolfalse
← SwitchNoticeBar →
  • Basic Example
  • Props
mCloud Design Mobile
Docs
Getting Started (or other categories)Guides (or other categories)API Reference (or other categories)
Community
User ShowcaseStack OverflowProject ChatTwitter
More
BlogGitHubStar
Facebook Open Source
Copyright © 2019 Your Name or Your Company Name