react-toolbox/components/input/readme.md

57 lines
3.0 KiB
Markdown
Raw Normal View History

2015-07-01 09:38:07 +03:00
# Input
2015-11-01 10:41:40 +03:00
Although we are calling then Inputs they actually correspond to Material Design [Text fields](https://www.google.com/design/spec/components/text-fields.html). It allows a user to input text and it's the base for other components like the autocomplete.
<!-- example -->
```jsx
import Input from 'react-toolbox/lib/input';
2015-07-01 09:38:07 +03:00
2015-11-08 01:38:26 +03:00
class InputTest extends React.Component {
state = { name: '', phone: '', email: '' };
handleChange = (name, event) => {
const newState = {};
newState[`${name}`] = event.target.value;
this.setState(newState);
};
render () {
return (
<section>
<Input type='text' label='Name' name='name' value={this.state.name} onChange={this.handleChange.bind(this, 'name')} />
<Input type='text' label='Disabled field' disabled />
<Input type='email' label='Email address' icon='email' />
<Input type='tel' label='Phone' name='phone' icon='phone' value={this.state.withIcon} onChange={this.handleChange.bind(this, 'phone')} />
</section>
);
}
}
2015-07-01 09:38:07 +03:00
```
## Properties
| Name | Type | Default | Description|
2015-11-01 10:41:40 +03:00
|:-----|:-----|:-----|:-----|
| `className` | `String` |`''` | Sets a class name to give custom styles.|
| `disabled` | `Boolean` | `false` | If true, component will be disabled.|
| `error` | `String` | | Give an error string to display under the field.|
| `icon` | `String` | | Name of an icon to use as a label for the input.|
| `floating` | `Boolean` | `true` | Indicates if the label is floating in the input field or not.|
| `label` | `String` | | The text string to use for the floating label element.|
2015-11-18 11:19:58 +03:00
| `maxLength` | `number` | |Specifies the maximum number of characters allowed in the component.|
2015-11-01 10:41:40 +03:00
| `multiline` | `Boolean` | `false` | If true, a textarea element will be rendered. The textarea also grows and shrinks according to the number of lines.|
| `onBlur` | `Function` | | Callback function that is fired when components is blured.|
| `onChange` | `Function` | | Callback function that is fired when the components's value changes.|
| `onFocus` | `Function` | | Callback function that is fired when components 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 value.|
| `type` | `String` | `text` | Type of the input element. It can be a valid HTML5 input type|
2015-11-08 01:38:26 +03:00
| `value` | `String` | | Current value of the input element.|
2015-07-01 09:38:07 +03:00
## Methods
2015-11-08 01:38:26 +03:00
The input is stateless but it includes two methods to be able to communicate with the DOM input node:
2015-08-10 13:13:44 +03:00
2015-11-01 10:41:40 +03:00
- `blur` to blur the input field.
- `focus` to focus the input field.