Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
refactor(textarea): align 'on' function handlers
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `onChange` is called with two parameters:
First parameter an object with properties for `checked`, `name`, and
`value`.
The second is the React `event` object.
  • Loading branch information
varl committed Nov 20, 2019
1 parent 8aeaf64 commit 267b088
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions src/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,51 @@ export class TextArea extends Component {
}
}

handleChange = e => {
const { onChange, readOnly, disabled } = this.props

if (disabled || readOnly) {
return
}

if (onChange) {
onChange(
{
value: e.target.value,
name: this.props.name,
},
e
)
}
}

handleBlur = e => {
const { onBlur, disabled } = this.props

if (disabled) {
return
}

if (onBlur) {
onBlur(e)
}
}

handleFocus = e => {
const { onFocus, disabled } = this.props

if (disabled) {
return
}

if (onFocus) {
onFocus(e)
}
}

render() {
const {
className,
onChange,
onFocus,
onBlur,
dense,
disabled,
readOnly,
Expand Down Expand Up @@ -113,9 +152,9 @@ export class TextArea extends Component {
disabled={disabled}
readOnly={readOnly}
tabIndex={tabIndex}
onFocus={onFocus}
onBlur={onBlur}
onChange={onChange}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
onChange={this.handleChange}
rows={rows}
className={cx({
dense,
Expand Down Expand Up @@ -160,7 +199,7 @@ TextArea.defaultProps = {
* @static
*
* @prop {string} name
* @prop {function} onChange
* @prop {function} [onChange] - called with the signature `object, event`
* @prop {function} [onBlur]
* @prop {function} [onFocus]
* @prop {string} [className]
Expand Down Expand Up @@ -191,7 +230,7 @@ TextArea.propTypes = {

className: propTypes.string,

onChange: propTypes.func.isRequired,
onChange: propTypes.func,
onFocus: propTypes.func,
onBlur: propTypes.func,

Expand Down

0 comments on commit 267b088

Please sign in to comment.