-
Notifications
You must be signed in to change notification settings - Fork 382
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
Remove react-autosize-textarea #10543
Changes from 1 commit
ba94448
ba7a6c0
2f60212
af1013f
3d67fc8
17c81df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
import TextareaAutosize from 'components/textarea-autosize'; | ||
import { CommentableMetaJson } from 'interfaces/comment-json'; | ||
import { action, computed, makeObservable, observable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import Comment from 'models/comment'; | ||
import core from 'osu-core-singleton'; | ||
import * as React from 'react'; | ||
import TextareaAutosize from 'react-autosize-textarea'; | ||
import { classWithModifiers, Modifiers } from 'utils/css'; | ||
import { InputEventType, makeTextAreaHandler, TextAreaCallback } from 'utils/input-handler'; | ||
import { trans } from 'utils/lang'; | ||
|
@@ -115,9 +115,9 @@ export default class CommentEditor extends React.Component<Props> { | |
} | ||
|
||
<TextareaAutosize | ||
ref={this.textarea} | ||
className={`${bn}__message`} | ||
disabled={!this.canComment || this.posting} | ||
innerRef={this.textarea} | ||
onChange={this.onChange} | ||
onKeyDown={this.handleKeyDown} | ||
placeholder={this.placeholder} | ||
|
@@ -188,7 +188,7 @@ export default class CommentEditor extends React.Component<Props> { | |
}; | ||
|
||
@action | ||
private readonly onChange = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
private readonly onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
this.message = e.currentTarget.value; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
import autosize from 'autosize'; | ||
import React from 'react'; | ||
|
||
interface Props extends React.TextareaHTMLAttributes<HTMLTextAreaElement> { | ||
async: boolean; | ||
innerRef?: React.RefObject<HTMLTextAreaElement>; | ||
maxRows?: number; | ||
} | ||
|
||
export default class TextareaAutosize extends React.Component<Props> { | ||
static readonly defaultProps = { | ||
async: false, | ||
rows: 1, | ||
}; | ||
|
||
private lineHeight?: number; | ||
private ref = this.props.innerRef ?? React.createRef<HTMLTextAreaElement>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be a getter instead so the value doesn't potentially get outdated when the props change? (although probably practically impossible? also there are a bunch of other ref-related things that's being set once in componentDidMount and assumed being the same in componentDidUpdate) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refs aren't managed by React other than committing a value to it after render, so messing with a ref wouldn't normally be triggering renders anyway |
||
|
||
private get maxHeight() { | ||
return this.props.maxRows != null && this.lineHeight | ||
? Math.ceil(this.lineHeight * this.props.maxRows) | ||
: null; | ||
} | ||
|
||
componentDidMount() { | ||
if (this.ref.current == null) return; | ||
|
||
if (this.props.maxRows != null) { | ||
this.lineHeight = parseFloat(window.getComputedStyle(this.ref.current).getPropertyValue('line-height')); | ||
} | ||
|
||
if (this.props.maxRows != null || this.props.async) { | ||
window.setTimeout(() => { | ||
if (this.ref.current != null) { | ||
autosize(this.ref.current); | ||
} | ||
}, 0); | ||
} else { | ||
autosize(this.ref.current); | ||
} | ||
} | ||
|
||
componentDidUpdate() { | ||
if (this.ref.current == null) return; | ||
autosize.update(this.ref.current); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.ref.current == null) return; | ||
autosize.destroy(this.ref.current); | ||
} | ||
|
||
render() { | ||
const { async, innerRef, maxRows, style, ...otherProps } = this.props; | ||
|
||
const maxHeight = this.maxHeight; | ||
|
||
return ( | ||
<textarea | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old one uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. white box appears to be a change in |
||
ref={this.ref} | ||
style={maxHeight != null ? { ...style, maxHeight } : style} | ||
{...otherProps} | ||
/> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,6 +327,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a" | ||
integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA== | ||
|
||
"@types/autosize@^4.0.1": | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/autosize/-/autosize-4.0.1.tgz#999a7c305b96766248044ebaac1a0299961f3b61" | ||
integrity sha512-iPJT/FCaSO79G6j+9n6gmFc5nhxZ1gDrA2UAvb5FslJ6FJQZnDfbBU0qp5vpp0Cbjj7+gOyjuWZ7RrXvRuETaA== | ||
|
||
"@types/bootstrap@^3.3.0": | ||
version "3.4.0" | ||
resolved "https://registry.yarnpkg.com/@types/bootstrap/-/bootstrap-3.4.0.tgz#7e74a2421b3984ce53ab459e979a99a78dd802c6" | ||
|
@@ -1318,10 +1323,10 @@ autoprefixer@^9.8.6: | |
postcss "^7.0.32" | ||
postcss-value-parser "^4.1.0" | ||
|
||
autosize@^4.0.2: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/autosize/-/autosize-4.0.2.tgz#073cfd07c8bf45da4b9fd153437f5bafbba1e4c9" | ||
integrity sha512-jnSyH2d+qdfPGpWlcuhGiHmqBJ6g3X+8T+iRwFrHPLVcdoGJE/x6Qicm6aDHfTsbgZKxyV8UU/YB2p4cjKDRRA== | ||
autosize@^6.0.1: | ||
version "6.0.1" | ||
resolved "https://registry.yarnpkg.com/autosize/-/autosize-6.0.1.tgz#64ee78dd7029be959eddd3afbbd33235b957e10f" | ||
integrity sha512-f86EjiUKE6Xvczc4ioP1JBlWG7FKrE13qe/DxBCpe8GCipCq2nFw73aO8QEBKHfSbYGDN5eB9jXWKen7tspDqQ== | ||
|
||
aws-sign2@~0.7.0: | ||
version "0.7.0" | ||
|
@@ -2002,11 +2007,6 @@ compute-scroll-into-view@^1.0.17: | |
resolved "https://registry.yarnpkg.com/compute-scroll-into-view/-/compute-scroll-into-view-1.0.17.tgz#6a88f18acd9d42e9cf4baa6bec7e0522607ab7ab" | ||
integrity sha512-j4dx+Fb0URmzbwwMUrhqWM2BEWHdFGx+qZ9qqASHRPqvTYdqvWnHg0H1hIbcyLnvgnoNAVMlwkepyqM3DaIFUg== | ||
|
||
computed-style@~0.1.3: | ||
version "0.1.4" | ||
resolved "https://registry.yarnpkg.com/computed-style/-/computed-style-0.1.4.tgz#7f344fd8584b2e425bedca4a1afc0e300bb05d74" | ||
integrity sha1-fzRP2FhLLkJb7cpKGvwOMAuwXXQ= | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|
@@ -4953,13 +4953,6 @@ levn@^0.4.1: | |
prelude-ls "^1.2.1" | ||
type-check "~0.4.0" | ||
|
||
line-height@^0.3.1: | ||
version "0.3.1" | ||
resolved "https://registry.yarnpkg.com/line-height/-/line-height-0.3.1.tgz#4b1205edde182872a5efa3c8f620b3187a9c54c9" | ||
integrity sha1-SxIF7d4YKHKl76PI9iCzGHqcVMk= | ||
dependencies: | ||
computed-style "~0.1.3" | ||
|
||
lines-and-columns@^1.1.6: | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632" | ||
|
@@ -6602,7 +6595,7 @@ promise-inflight@^1.0.1: | |
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" | ||
integrity sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g== | ||
|
||
prop-types@^15.0.0, prop-types@^15.5.6, prop-types@^15.6.2, prop-types@^15.8.1: | ||
prop-types@^15.0.0, prop-types@^15.6.2, prop-types@^15.8.1: | ||
version "15.8.1" | ||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5" | ||
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg== | ||
|
@@ -6730,15 +6723,6 @@ [email protected]: | |
iconv-lite "0.4.24" | ||
unpipe "1.0.0" | ||
|
||
[email protected]: | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/react-autosize-textarea/-/react-autosize-textarea-7.0.0.tgz#4f633e4238de7ba73c1da8fdc307353c50f1c5ab" | ||
integrity sha512-rGQLpGUaELvzy3NKzp0kkcppaUtZTptsyR0PGuLotaJDjwRbT0DpD000yCzETpXseJQ/eMsyVGDDHXjXP93u8w== | ||
dependencies: | ||
autosize "^4.0.2" | ||
line-height "^0.3.1" | ||
prop-types "^15.5.6" | ||
|
||
react-dom-factories@^1.0.0: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/react-dom-factories/-/react-dom-factories-1.0.2.tgz#eb7705c4db36fb501b3aa38ff759616aa0ff96e0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like the maximum rows option doesn't get applied correctly