Browse Source

Introduce react-textarea-autosize instead of using style.height side effects (#3334)

closed-social-v3
Eugen Rochko 7 years ago
committed by GitHub
parent
commit
c48772fd3f
4 changed files with 10 additions and 11 deletions
  1. +3
    -10
      app/javascript/mastodon/components/autosuggest_textarea.js
  2. +0
    -1
      app/javascript/mastodon/features/compose/components/compose_form.js
  3. +1
    -0
      package.json
  4. +6
    -0
      yarn.lock

+ 3
- 10
app/javascript/mastodon/components/autosuggest_textarea.js View File

@ -4,6 +4,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { isRtl } from '../rtl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import Textarea from 'react-textarea-autosize';
const textAtCursorMatchesToken = (str, caretPosition) => {
let word;
@ -69,10 +70,6 @@ class AutosuggestTextarea extends ImmutablePureComponent {
this.props.onSuggestionsClearRequested();
}
// auto-resize textarea
e.target.style.height = 'auto';
e.target.style.height = `${e.target.scrollHeight}px`;
this.props.onChange(e);
}
@ -160,10 +157,6 @@ class AutosuggestTextarea extends ImmutablePureComponent {
}
}
reset () {
this.textarea.style.height = 'auto';
}
render () {
const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus } = this.props;
const { suggestionsHidden, selectedSuggestion } = this.state;
@ -175,8 +168,8 @@ class AutosuggestTextarea extends ImmutablePureComponent {
return (
<div className='autosuggest-textarea'>
<textarea
ref={this.setTextarea}
<Textarea
inputRef={this.setTextarea}
className='autosuggest-textarea__textarea'
disabled={disabled}
placeholder={placeholder}

+ 0
- 1
app/javascript/mastodon/features/compose/components/compose_form.js View File

@ -67,7 +67,6 @@ class ComposeForm extends ImmutablePureComponent {
}
handleSubmit = () => {
this.autosuggestTextarea.reset();
this.props.onSubmit();
}

+ 1
- 0
package.json View File

@ -90,6 +90,7 @@
"react-router": "^2.8.0",
"react-router-scroll": "^0.3.2",
"react-simple-dropdown": "^1.1.4",
"react-textarea-autosize": "^5.0.6",
"react-toggle": "^2.1.1",
"redis": "^2.6.5",
"redux": "^3.6.0",

+ 6
- 0
yarn.lock View File

@ -5590,6 +5590,12 @@ react-test-renderer@^15.5.4:
fbjs "^0.8.9"
object-assign "^4.1.0"
react-textarea-autosize@^5.0.6:
version "5.0.6"
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-5.0.6.tgz#a3742e0a319484021b4dbfa1519df287768f2133"
dependencies:
prop-types "^15.5.8"
react-toggle@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/react-toggle/-/react-toggle-2.1.1.tgz#80600a64417a1acc8aaa4c1477f7fbdb88b988fb"

Loading…
Cancel
Save