Input 输入框

注:

  • 支持表单,具体可参考 Form
import { TaInput, TaCell, TaGroup, showToast } from '@/index'

export default function ExpInput() {
  function onInput(value: string) {
    showToast(`当前值为:${value}`)
  }

  return (
    <>
      <TaGroup title="基础用法">
        <TaInput type="text" focus placeholder="请输入文本" />
        <TaInput type="text" value="禁用" disabled />
        <TaInput type="text" placeholder="showLimit=true" showLimit showClear />
      </TaGroup>
      <TaGroup title="textarea">
        <TaInput
          type="textarea"
          placeholder="showLimit=true"
          showLimit
          maxlength={200}
        />
      </TaGroup>
      <TaGroup title="Slot prepend/append">
        <TaInput
          type="text"
          focus
          placeholder="请输入网址"
          renderPrepend={() => 'https://'}
        />
        <TaInput
          type="text"
          focus
          placeholder="请输入网址"
          renderAppend={() => '.com'}
        />
      </TaGroup>
      <TaGroup title="与 Cell 组合">
        <TaCell label="文本">
          <TaInput type="text" placeholder="请输入文本" />
        </TaCell>
      </TaGroup>
      <TaGroup title="设置 type 类型">
        <TaCell label="文本 text">
          <TaInput type="text" placeholder="请输入文本" />
        </TaCell>
        <TaCell label="电话 tel">
          <TaInput type="tel" placeholder="请输入电话" />
        </TaCell>
        <TaCell label="整数 digit">
          <TaInput type="digit" placeholder="请输入整数" />
        </TaCell>
        <TaCell label="数字 number">
          <TaInput type="number" placeholder="请输入数字" />
        </TaCell>
        <TaCell label="搜索 search">
          <TaInput type="search" placeholder="请输入要搜索的内容" />
        </TaCell>
        <TaCell label="密码 password">
          <TaInput type="password" placeholder="请输入密码" />
        </TaCell>
        <TaCell label="文本 textarea">
          <TaInput type="textarea" placeholder="请输入多行文本" />
        </TaCell>
      </TaGroup>
      <TaGroup title="其他">
        <TaCell label="只读 readonly">
          <TaInput type="text" value="只读文本" readonly />
        </TaCell>
        <TaCell label="禁用 disabled">
          <TaInput type="text" value="禁用文本" disabled />
        </TaCell>
        <TaCell label="可清除 showClear">
          <TaInput
            type="text"
            placeholder="请输入文本"
            value="文本内容"
            showClear
          />
        </TaCell>
      </TaGroup>
      <TaGroup title="事件监听">
        <TaCell label="input">
          <TaInput
            type="text"
            placeholder="请输入文本"
            showClear
            onInput={onInput}
          />
        </TaCell>
        <TaCell label="change">
          <TaInput
            type="text"
            placeholder="请输入文本"
            showClear
            onChange={onInput}
          />
        </TaCell>
      </TaGroup>
    </>
  )
}

Import

import { TaInput } from 'tantalum-ui-mobile-react'

具体的引入方式可以参考引入组件

Props

属性类型默认值必填说明
valuestring | number''
namestring标识
typestring'text'类型
placeholderstring输入框为空时占位符
disabledbooleanfalse是否禁用
readonlybooleanfalse是否只读
maxlengthstring | number140最大长度
focusbooleanfalse是否获取焦点
showClearbooleanfalse是否展示清除图标

type 的合法值

说明
text文本
digit整数
number数字
password密码
search搜索
password密码

Events

事件描述回调函数参数
onInput输入值改变时触发value: string
onChange输入值改变且失焦后触发,含点击清空按钮value: string
onFocus获取焦点时触发e: FocusEvent
onBlur移出焦点时触发e: FocusEvent

Slots

前置元素(renderPrepend)

<TaInput
  type="text"
  focus
  placeholder="请输入网址"
  renderPrepend={() => 'https://'}
/>

注:也可以传入 Icon,比如常见的搜索。

后置元素(renderAppend)

<TaInput
  type="text"
  focus
  placeholder="请输入网址"
  renderAppend={() => '.com'}
/>