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 support for line-breaks and multiline #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ If your input uses custom font sizes, you will need to provide the custom size t
### Uncontrolled input
`AutosizeInput` is a [controlled input](https://facebook.github.io/react/docs/forms.html#controlled-components) and depends on the `value` prop to work as intended. It does not support being used as an uncontrolled input.

### Copy&Paste and line-breaks
The `input` tag does always strip line-breaks on paste. To overcome this restriction, you can pass the `inputIsTextArea={true}` prop.

## License

Copyright (c) 2018 Jed Watson. [MIT](LICENSE) License.
7 changes: 4 additions & 3 deletions dist/react-input-autosize.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ var sizerStyle = {
whiteSpace: 'pre'
};

var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'minWidth', 'onAutosize', 'placeholderIsMinWidth'];
var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'inputIsTextArea', 'minWidth', 'onAutosize', 'placeholderIsMinWidth'];

var cleanInputProps = function cleanInputProps(inputProps) {
INPUT_PROPS_BLACKLIST.forEach(function (field) {
Expand Down Expand Up @@ -373,7 +373,7 @@ var AutosizeInput = function (_Component) {
var injectStyles = this.props.injectStyles;

return isIE && injectStyles ? React.createElement('style', { dangerouslySetInnerHTML: {
__html: 'input#' + this.state.inputId + '::-ms-clear {display: none;}'
__html: 'input#' + this.state.inputId + '::-ms-clear, textarea#' + this.state.inputId + '::-ms-clear {display: none;}'
} }) : null;
}
}, {
Expand Down Expand Up @@ -405,7 +405,7 @@ var AutosizeInput = function (_Component) {
'div',
{ className: this.props.className, style: wrapperStyle },
this.renderStyles(),
React.createElement('input', _extends({}, inputProps, { ref: this.inputRef })),
this.props.inputIsTextArea ? React.createElement('textarea', _extends({}, inputProps, { ref: this.inputRef, wrap: 'off' })) : React.createElement('input', _extends({}, inputProps, { ref: this.inputRef })),
React.createElement(
'div',
{ ref: this.sizerRef, style: sizerStyle },
Expand All @@ -432,6 +432,7 @@ AutosizeInput.propTypes = {
inputClassName: PropTypes.string, // className for the input element
inputRef: PropTypes.func, // ref callback for the input element
inputStyle: PropTypes.object, // css styles for the input element
inputIsTextArea: PropTypes.bool, // switch to textarea instead of input (don't strip line-breaks)
minWidth: PropTypes.oneOfType([// minimum width for input element
PropTypes.number, PropTypes.string]),
onAutosize: PropTypes.func, // onAutosize handler: function(newWidth) {}
Expand Down
7 changes: 4 additions & 3 deletions dist/react-input-autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var sizerStyle = {
whiteSpace: 'pre'
};

var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'minWidth', 'onAutosize', 'placeholderIsMinWidth'];
var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'inputIsTextArea', 'minWidth', 'onAutosize', 'placeholderIsMinWidth'];

var cleanInputProps = function cleanInputProps(inputProps) {
INPUT_PROPS_BLACKLIST.forEach(function (field) {
Expand Down Expand Up @@ -379,7 +379,7 @@ var AutosizeInput = function (_Component) {
var injectStyles = this.props.injectStyles;

return isIE && injectStyles ? React__default.createElement('style', { dangerouslySetInnerHTML: {
__html: 'input#' + this.state.inputId + '::-ms-clear {display: none;}'
__html: 'input#' + this.state.inputId + '::-ms-clear, textarea#' + this.state.inputId + '::-ms-clear {display: none;}'
} }) : null;
}
}, {
Expand Down Expand Up @@ -411,7 +411,7 @@ var AutosizeInput = function (_Component) {
'div',
{ className: this.props.className, style: wrapperStyle },
this.renderStyles(),
React__default.createElement('input', _extends({}, inputProps, { ref: this.inputRef })),
this.props.inputIsTextArea ? React__default.createElement('textarea', _extends({}, inputProps, { ref: this.inputRef, wrap: 'off' })) : React__default.createElement('input', _extends({}, inputProps, { ref: this.inputRef })),
React__default.createElement(
'div',
{ ref: this.sizerRef, style: sizerStyle },
Expand All @@ -438,6 +438,7 @@ AutosizeInput.propTypes = {
inputClassName: PropTypes.string, // className for the input element
inputRef: PropTypes.func, // ref callback for the input element
inputStyle: PropTypes.object, // css styles for the input element
inputIsTextArea: PropTypes.bool, // switch to textarea instead of input (don't strip line-breaks)
minWidth: PropTypes.oneOfType([// minimum width for input element
PropTypes.number, PropTypes.string]),
onAutosize: PropTypes.func, // onAutosize handler: function(newWidth) {}
Expand Down
2 changes: 1 addition & 1 deletion dist/react-input-autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/dist/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/dist/common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html> <head> <title>React-Autosize-Input Example</title> <link rel=stylesheet href=example.css> </head> <body> <div class=container> <h1>React Autosize Input</h1> <h2><a href=http://github.com/JedWatson/react-input-autosize>View project on GitHub</a></h2> <form><div id=app></div></form> <div class=hint> Type in the text fields above to test the auto-size input. </div> <div class=footer> Copyright &copy; Jed Watson 2018. MIT Licensed. </div> </div> <script src=common.js></script> <script src=app.js></script> </body>
<!doctype html> <head> <title>React-Autosize-Input Example</title> <link rel=stylesheet href=example.css> </head> <body> <div class=container> <h1>React Autosize Input</h1> <h2><a href=http://github.com/JedWatson/react-input-autosize>View project on GitHub</a></h2> <form><div id=app></div></form> <div class=hint> Type in the text fields above to test the auto-size input. </div> <div class=footer> Copyright &copy; Jed Watson 2018. MIT Licensed. </div> </div> <script src=common.js></script> <script src=app.js></script> </body>
Loading