Skip to content

Commit

Permalink
feat(TextArea): Added TextArea element
Browse files Browse the repository at this point in the history
  • Loading branch information
mBourges committed Nov 22, 2016
1 parent 36f8b9d commit 8b446b6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/textArea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import './textArea.scss';

class TextArea extends React.Component {
constructor(props) {
super(props);

this.handleChange = this.handleChange.bind(this);
this.handleBlur = this.handleBlur.bind(this);
}

componentDidMount() {
window.componentHandler.upgradeElement(this.root);
}

componentWillUnmount() {
window.componentHandler.downgradeElements(this.root);
}

handleChange(event) {
const { onChange } = this.props;
const { id, value } = event.target;

onChange(id, value);
}

handleBlur(event) {
const { onBlur } = this.props;
const { id, value } = event.target;

if (onBlur) {
onBlur(id, value);
}
}

render() {
const { id, label, onChange, onBlur, ...rest } = this.props; // eslint-disable-line no-unused-vars
const { required } = rest;

return (<div ref={ (node) => { this.root = node; } } className="mdl-textfield mdl-js-textfield fullwidth">
<textarea className="mdl-textfield__input" type="text" id={ id } onChange={ this.handleChange } onBlur={ this.handleBlur } { ...rest } />
<label className="mdl-textfield__label" htmlFor={ id }>{ label }</label>
{ required && <span className="mdl-textfield__error">{ label } is required</span> }
</div>);
}
}

TextArea.defaultProps = {
rows: 5
};

TextArea.propTypes = {
id: React.PropTypes.string.isRequired,
label: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func.isRequired,
onBlur: React.PropTypes.func,
autoFocus: React.PropTypes.bool,
required: React.PropTypes.bool,
rows: React.PropTypes.number
};

export default TextArea;
5 changes: 5 additions & 0 deletions src/textArea.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:global(.mdl-textfield) {
&.fullwidth {
width: 100%;
}
}

0 comments on commit 8b446b6

Please sign in to comment.