Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] fix textarea maxRows #4286

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/TextField/EnhancedTextarea.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {Component, PropTypes} from 'react';
import EventListener from 'react-event-listener';
import keycode from 'keycode';

const rowsHeight = 24;

Expand Down Expand Up @@ -35,6 +36,7 @@ class EnhancedTextarea extends Component {
disabled: PropTypes.bool,
onChange: PropTypes.func,
onHeightChange: PropTypes.func,
onKeyDown: PropTypes.func,
rows: PropTypes.number,
rowsMax: PropTypes.number,
shadowStyle: PropTypes.object,
Expand Down Expand Up @@ -120,10 +122,20 @@ class EnhancedTextarea extends Component {
}
};

handleKeyDown = (event) => {
const shadow = this.refs.shadow;

if (keycode(event) === 'enter' &&
shadow.scrollHeight >= this.props.rowsMax * rowsHeight) {
event.preventDefault();
}
}

render() {
const {
onChange, // eslint-disable-line no-unused-vars
onHeightChange, // eslint-disable-line no-unused-vars
onKeyDown, // eslint-disable-line no-unused-vars
rows, // eslint-disable-line no-unused-vars
shadowStyle,
style,
Expand Down Expand Up @@ -161,6 +173,7 @@ class EnhancedTextarea extends Component {
rows={this.props.rows}
style={prepareStyles(textareaStyles)}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
/>
</div>
);
Expand Down