-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathTextarea.js
More file actions
60 lines (53 loc) · 1.51 KB
/
Textarea.js
File metadata and controls
60 lines (53 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import FormElement from './FormElement';
import { uuid } from './util';
export default class Textarea extends Component {
constructor() {
super();
this.state = { id: `form-element-${uuid()}` };
this.onChange = this.onChange.bind(this);
}
onChange(e) {
const value = e.target.value;
if (this.props.onChange) {
this.props.onChange(e, value);
}
}
render() {
const id = this.props.id || this.state.id;
const { label, required, error, totalCols, cols, ...props } = this.props;
if (label || required || error || totalCols || cols) {
const formElemProps = { id, label, required, error, totalCols, cols };
return (
<FormElement { ...formElemProps }>
<Textarea { ...{ ...props, id } } />
</FormElement>
);
}
const { className, textareaRef, ...pprops } = props;
const taClassNames = classnames(className, 'slds-input');
return (
<textarea
id={ id }
ref={ textareaRef }
className={ taClassNames }
onChange={ this.onChange }
{ ...pprops }
/>
);
}
}
Textarea.propTypes = {
id: PropTypes.string,
className: PropTypes.string,
label: PropTypes.string,
required: PropTypes.bool,
error: FormElement.propTypes.error,
totalCols: PropTypes.number,
cols: PropTypes.number,
onChange: PropTypes.func,
textareaRef: PropTypes.func,
};
Textarea.isFormElement = true;