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

Add maxWidth Prop #71

Closed
wants to merge 1 commit 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
8 changes: 8 additions & 0 deletions src/AutosizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const AutosizeInput = React.createClass({
defaultValue: React.PropTypes.any, // default field value
inputClassName: React.PropTypes.string, // className for the input element
inputStyle: React.PropTypes.object, // css styles for the input element
maxWidth: React.PropTypes.oneOfType([ // maximum width for input element
React.PropTypes.number,
React.PropTypes.string,
]),
minWidth: React.PropTypes.oneOfType([ // minimum width for input element
React.PropTypes.number,
React.PropTypes.string,
Expand Down Expand Up @@ -74,6 +78,9 @@ const AutosizeInput = React.createClass({
} else {
newInputWidth = this.refs.sizer.scrollWidth + 2;
}
if (newInputWidth > this.props.maxWidth) {
newInputWidth = this.props.maxWidth;
}
if (newInputWidth < this.props.minWidth) {
newInputWidth = this.props.minWidth;
}
Expand Down Expand Up @@ -115,6 +122,7 @@ const AutosizeInput = React.createClass({
// ensure props meant for `AutosizeInput` don't end up on the `input`
delete inputProps.inputClassName;
delete inputProps.inputStyle;
delete inputProps.maxWidth;
delete inputProps.minWidth;
delete inputProps.placeholderIsMinWidth;
return (
Expand Down