react-toolbox/components/input
Vitaliy Filippov ba3993c811 Fix table styles, pass `style` to top-level element in inputs 2019-05-07 16:50:56 +03:00
..
Input.d.ts Typescript definitions validation (#1163) 2017-09-01 17:51:41 +02:00
Input.js Fix table styles, pass `style` to top-level element in inputs 2019-05-07 16:50:56 +03:00
config.css update defaults in input component config.css 2017-11-27 15:58:49 -07:00
index.d.ts Restructure typescript definitions (#1114) 2017-01-18 08:37:37 +01:00
index.js Update dependencies and linter (#1180) 2017-01-26 18:05:32 +01:00
readme.md Update URLs to new .io domain 2017-11-16 19:11:31 +01:00
theme.css Merge pull request #1627 from olegstepura/disabled-input 2018-01-25 09:02:30 +01:00

readme.md

Input

Although we are calling them Inputs they actually correspond to Material Design Text fields. It allows a user to input text and it's the base for other components like the autocomplete.

import Input from 'react-toolbox/lib/input';

class InputTest extends React.Component {
  state = { name: '', phone: '', email: '', hint: '' };

  handleChange = (value, ev) => {
    this.setState({ [ev.target.name]: value });
  };

  render () {
    return (
      <section>
        <Input type='text' label='Name' name='name' value={this.state.name} onChange={this.handleChange} maxLength={16 } />
        <Input type='text' label='Disabled field' disabled />
        <Input type='email' label='Email address' name='email' icon='email' value={this.state.email} onChange={this.handleChange} />
        <Input type='tel' label='Phone' name='phone' icon='phone' value={this.state.phone} onChange={this.handleChange} />
        <Input type='text' label='Required Field' name='hint' hint='With Hint' required value={this.state.hint} onChange={this.handleChange} icon={<span>J</span>} />
      </section>
    );
  }
}

If you want to provide a theme via context, the component key is RTInput.

Properties

Name Type Default Description
className String '' Sets a class name to give custom styles.
disabled Boolean false If true, component will be disabled.
error String or Node Give an error node to display under the field.
floating Boolean true Indicates if the label is floating in the input field or not.
hint String or Node '' The text string to use for hint text element.
icon String or Element Name of an icon to use as a label for the input.
label String or Node The text string to use for the floating label element.
maxLength Number Specifies the maximum number of characters allowed in the component.
multiline Boolean false If true, a textarea element will be rendered. The textarea also grows and shrinks according to the number of lines.
rows Number The number of rows the multiline input field has.
onBlur Function Callback function that is fired when component is blurred.
onChange Function Callback function that is fired when the component's value changes.
onFocus Function Callback function that is fired when component is focused.
onKeyPress Function Callback function that is fired when a key is pressed.
required Boolean false If true, the html input has a required attribute.
type String text Type of the input element. It can be a valid HTML5 input type
value Any Current value of the input element.

Theming

Name Description
bar Used for the bar under the input.
counter Used for the counter element.
disabled Added to the root class when input is disabled.
error Used for the text error.
errored Added to the root class when input is errored.
hidden Used when the input is hidden.
hint Used for the hint text.
icon Used for the icon in case the input has icon.
input Used as root class for the component.
inputElement Used for the HTML input element.
label Used for the label when the input has a label.
required Used in case the input is required.
withIcon Added to the root class if the input has icon.

Methods

The Input component has some imperative methods that are used as a bypass to the native rendered DOM element. To call this methods you will need to retrieve the instance of the component. Check the Install section for details on how to do this. The methods included for the Input are:

  • blur used to blur the input element.
  • focus used to focus the input element.