rax-textinput
TextInput component for Rax.
Last updated 7 years ago by recover758126 .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ npm install rax-textinput 
SYNC missed versions from official npm registry.

npm

描述: TextInput 是唤起用户输入的基础组件。

当定义 multiline 输入多行文字时其功能相当于 textarea。

安装

$ npm install rax-textinput --save

属性

注: 1、支持列表中的 browser代表 h5 weex代表 weex miniApp代表小程序

属性 类型 默认值 必填 描述 支持
multiline boolen - false 定义该属性文本框可以输入多行文字 browser weex miniApp
accessibilityLabel string - false 为元素添加标识 browser
autoComplete boolen - false 添加开启自动完成功能 browser weex
autoFocus boolen - false 添加开启获取焦点 browser weex miniApp
onAppear function - false 当前元素可见时触发 browser weex miniApp
editable boolean - false 默认为 true 如果为 fase 则文本框不可编辑 browser weexminiApp
keyboardType string - false 设置弹出哪种软键盘 可用的值有default ascii-capable numbers-and-punctuation url number-pad phone-pad name-phone-pad email-address decimal-pad twitter web-search numeric browser weex
maxLength number - false 设置最大可输入值 browser weexminiApp
maxNumberOfLines number - false 当文本框为 mutiline 时设置最多的行数 browser weex
numberOfLines number - false 同上设置行数 browser weex
placeholder string - false 设置文本框提示 browser weexminiApp
password boolean - false 文本框内容密码显示 browser weexminiApp
secureTextEntry boolean - false 同上文本框内容密码显示 browser weexminiApp
value string - false 文本框的文字内容 (受控) browser weexminiApp
defaultValue string - false 文本框的文字内容(非受控) browser weexminiApp
onBlur function - false 文本框失焦时调用此函数。onBlur={() => console.log('失焦啦')} browser weexminiApp
onFocus function - false 文本框获得焦点时调用此函数 browser weexminiApp
onChange function - false 文本框内容变化时调用此函数(用户输入完成时触发。通常在 blur 事件之后) browser weexminiApp
onChangeText function - false 触发时机和onChange一致, 区别在于该函数的参数是文本框内容 browser weexminiApp
onInput function - false 文本框输入内容时调用此函数 browser weexminiApp

方法

focus()

取焦点方法(小程序不支持)

blur()

失去焦点方法(小程序不支持)

clear()

清除文本框内容(小程序不支持)

import { createElement, Component, render, createRef } from "rax";
import DU from "driver-universal";
import View from "rax-view";
import Text from "rax-text";
import TextInput from "rax-textinput";
const styles = {
  root: {
    width: 750,
    paddingTop: 20
  },
  container: {
    padding: 20,
    borderStyle: "solid",
    borderColor: "#dddddd",
    borderWidth: 1,
    marginLeft: 20,
    marginRight: 20,
    marginBottom: 10
  },
  default: {
    borderWidth: 1,
    borderColor: "#0f0f0f",
    flex: 1
  },
  eventLabel: {
    margin: 3,
    fontSize: 24
  },
  multiline: {
    borderWidth: 1,
    borderColor: "#0f0f0f",
    flex: 1,
    fontSize: 26,
    height: 100,
    padding: 8,
    marginBottom: 8
  },
  hashtag: {
    color: "blue",
    margin: 10,
    fontWeight: "bold"
  }
};
class TextAreaDemo extends Component {
  constructor(props) {
    super(props);
    this.state = {
      text: "Hello #World , Hello #Rax , Hello #天天好心情"
    };
  }

  render() {
    let delimiter = /\s+/;

    // split string
    let _text = this.state.text;
    let token,
      index,
      parts = [];
    while (_text) {
      delimiter.lastIndex = 0;
      token = delimiter.exec(_text);
      if (token === null) {
        break;
      }
      index = token.index;
      if (token[0].length === 0) {
        index = 1;
      }
      parts.push(_text.substr(0, index));
      parts.push(token[0]);
      index = index + token[0].length;
      _text = _text.slice(index);
    }
    parts.push(_text);

    let hashtags = [];
    parts.forEach(text => {
      if (/^#/.test(text)) {
        hashtags.push(
          <Text key={text} style={styles.hashtag}>
            {text}
          </Text>
        );
      }
    });

    return (
      <View style={styles.container}>
        <TextInput
          multiline={true}
          numberOfLines={3}
          style={styles.multiline}
          value={this.state.text}
          onChangeText={text => {
            this.setState({ text });
          }}
        />
        <View style={{ flexDirection: "row", flexWrap: "wrap" }}>
          {hashtags}
        </View>
      </View>
    );
  }
}

class App extends Component {
  state = {
    value: "I am value",
    curText: "<No Event>",
    prevText: "<No Event>",
    prev2Text: "<No Event>",
    prev3Text: "<No Event>"
  };

  inputRef = createRef();

  updateText = text => {
    this.setState(state => {
      return {
        curText: text,
        prevText: state.curText,
        prev2Text: state.prevText,
        prev3Text: state.prev2Text
      };
    });
  };

  render() {
    // define delimiter
    return (
      <View style={styles.root}>
        <View style={styles.container}>
          <TextInput
            autoCapitalize="none"
            placeholder="Enter text to see events"
            autoCorrect={false}
            // onFocus={() => this.updateText('onFocus')}
            // onBlur={() => this.updateText('onBlur')}
            onChange={event => {
              this.updateText("onChange text: " + event.nativeEvent.text);
            }}
            // onInput={event =>
            //   this.updateText('onInput text: ' + event.nativeEvent.text)
            // }
            style={styles.default}
          />

          <Text style={styles.eventLabel}>
            {this.state.curText}
            {"\n"}
            (prev: {this.state.prevText}){"\n"}
            (prev2: {this.state.prev2Text}){"\n"}
            (prev3: {this.state.prev3Text})
          </Text>
        </View>

        <View style={styles.container}>
          <TextInput
            placeholder="Enter text to see events"
            value={this.state.value}
            ref={this.inputRef}
            style={{
              width: 600,
              marginTop: 20,
              borderWidth: "2px",
              borderColor: "#dddddd",
              borderStyle: "solid"
            }}
            onChangeText={text => {
              this.setState({
                value: text
              });
            }}
          />

          <View
            style={{
              marginTop: 20
            }}
            onFocus={e => {
              this.setState({
                value: e.nativeEvent.text
              });
            }}
            onClick={() => {
              this.setState({
                value: "I am value"
              });
            }}
          >
            <Text>Reset</Text>
          </View>
        </View>
        <TextAreaDemo />
      </View>
    );
  }
}

render(<App />, document.body, { driver: DU });

Current Tags

  • 1.4.3-0                                ...           beta (5 years ago)
  • 1.4.6                                ...           latest (4 years ago)

103 Versions

  • 1.4.6                                ...           4 years ago
  • 1.4.5                                ...           4 years ago
  • 1.4.4                                ...           4 years ago
  • 1.4.3                                ...           5 years ago
  • 1.4.3-0                                ...           5 years ago
  • 1.4.3-beta.2                                ...           5 years ago
  • 1.4.3-beta.1                                ...           5 years ago
  • 1.4.2                                ...           5 years ago
  • 1.4.2-1                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.2-0                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.10-0                                ...           5 years ago
  • 1.3.9                                ...           6 years ago
  • 1.3.8                                ...           6 years ago
  • 1.3.7                                ...           6 years ago
  • 1.3.6                                ...           6 years ago
  • 1.3.6-0                                ...           6 years ago
  • 1.3.5                                ...           6 years ago
  • 1.3.4                                ...           6 years ago
  • 1.3.3                                ...           6 years ago
  • 1.3.3-0                                ...           6 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.2-beta.1                                ...           6 years ago
  • 1.3.2-beta.0                                ...           6 years ago
  • 1.3.2-0                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.3.1-0                                ...           6 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.1                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.8                                ...           7 years ago
  • 1.1.7                                ...           7 years ago
  • 1.1.6                                ...           7 years ago
  • 1.1.5                                ...           7 years ago
  • 1.1.4                                ...           7 years ago
  • 1.1.3                                ...           7 years ago
  • 1.1.2                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.1-beta.3                                ...           7 years ago
  • 1.1.1-beta.2                                ...           7 years ago
  • 1.1.1-beta.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.1.0-0                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.1-beta.1                                ...           7 years ago
  • 1.0.1-miniapp.beta.0                                ...           7 years ago
  • 1.0.0                                ...           8 years ago
  • 1.0.0-beta.0                                ...           8 years ago
  • 0.6.5                                ...           8 years ago
  • 0.6.4                                ...           8 years ago
  • 0.6.3                                ...           9 years ago
  • 0.6.2                                ...           9 years ago
  • 0.6.1                                ...           9 years ago
  • 0.6.0                                ...           9 years ago
  • 0.5.4                                ...           9 years ago
  • 0.5.2                                ...           9 years ago
  • 0.5.1                                ...           9 years ago
  • 0.5.0                                ...           9 years ago
  • 0.4.20                                ...           9 years ago
  • 0.4.19                                ...           9 years ago
  • 0.4.18                                ...           9 years ago
  • 0.4.17                                ...           9 years ago
  • 0.4.16                                ...           9 years ago
  • 0.4.15                                ...           9 years ago
  • 0.5.0-beta                                ...           9 years ago
  • 0.4.14                                ...           9 years ago
  • 0.4.13                                ...           9 years ago
  • 0.4.12                                ...           9 years ago
  • 0.4.11                                ...           9 years ago
  • 0.4.10                                ...           9 years ago
  • 0.4.9                                ...           9 years ago
  • 0.4.8                                ...           9 years ago
  • 0.4.7                                ...           9 years ago
  • 0.4.6                                ...           9 years ago
  • 0.4.5                                ...           9 years ago
  • 0.4.4                                ...           9 years ago
  • 0.4.3                                ...           9 years ago
  • 0.4.2                                ...           9 years ago
  • 0.4.1                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
  • 0.3.8                                ...           9 years ago
  • 0.3.7                                ...           9 years ago
  • 0.3.6                                ...           9 years ago
  • 0.3.5                                ...           10 years ago
  • 0.3.4                                ...           10 years ago
  • 0.3.3                                ...           10 years ago
  • 0.3.2                                ...           10 years ago
  • 0.3.1                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.11                                ...           10 years ago
  • 0.2.10                                ...           10 years ago
  • 0.2.9                                ...           10 years ago
  • 0.2.8                                ...           10 years ago
  • 0.2.7                                ...           10 years ago
  • 0.2.6                                ...           10 years ago
  • 0.2.5                                ...           10 years ago
  • 0.2.4                                ...           10 years ago
  • 0.2.3                                ...           10 years ago
  • 0.2.2                                ...           10 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
Downloads
Total 146
Today 0
This Week 18
This Month 118
Last Day 0
Last Week 95
Last Month 19
Dependencies (6)
Dev Dependencies (16)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE