mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 10:02:47 +03:00
autoresize comment box
This commit is contained in:
parent
efc08504cb
commit
6e34df27e7
@ -23,16 +23,30 @@ class PostButton extends Component {
|
|||||||
export class CommentBox extends Component {
|
export class CommentBox extends Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.commentChange = this.commentChange.bind(this);
|
||||||
|
this.commentHeight = 54;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (!prevProps.enabled && this.props.enabled) {
|
if (!prevProps.enabled && this.props.enabled) {
|
||||||
if (this.textarea) {
|
if (this.commentInput) {
|
||||||
this.textarea.value = '';
|
this.commentInput.value = '';
|
||||||
|
this.commentInput.style.height = 54;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commentChange(evt) {
|
||||||
|
this.commentInput.style.height = 'auto';
|
||||||
|
let newHeight = (this.commentInput.scrollHeight < 54)
|
||||||
|
? 54 : this.commentInput.scrollHeight+2;
|
||||||
|
this.commentInput.style.height = newHeight+'px';
|
||||||
|
this.commentHeight = this.commentInput.style.height;
|
||||||
|
|
||||||
|
this.props.action(evt);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let textClass = (this.props.enabled)
|
let textClass = (this.props.enabled)
|
||||||
? "body-regular-400 w-100"
|
? "body-regular-400 w-100"
|
||||||
@ -45,12 +59,12 @@ export class CommentBox extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex-col w-100">
|
<div className="flex-col w-100">
|
||||||
<textarea className={textClass}
|
<textarea className={textClass}
|
||||||
ref={(el) => {this.textarea = el}}
|
ref={(el) => {this.commentInput = el}}
|
||||||
style={{resize: "none"}}
|
style={{resize: "none", height: this.commentHeight}}
|
||||||
type="text"
|
type="text"
|
||||||
name="commentBody"
|
name="commentBody"
|
||||||
defaultValue=''
|
defaultValue=''
|
||||||
onChange={this.props.action}
|
onChange={this.commentChange}
|
||||||
disabled={(!this.props.enabled)}>
|
disabled={(!this.props.enabled)}>
|
||||||
</textarea>
|
</textarea>
|
||||||
<PostButton
|
<PostButton
|
||||||
|
@ -45,8 +45,9 @@ export class Comment extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex-col fl">
|
<div className="flex-col fl">
|
||||||
<div className="label-small-mono gray-50">
|
<div className="label-small-mono gray-50">
|
||||||
<p className="fl" style={{width: 107}}>{this.props.ship}</p>
|
<p className="fl label-small-mono"
|
||||||
<p className="fl">{date}</p>
|
style={{width: 107}}>{this.props.ship}</p>
|
||||||
|
<p className="fl label-small-mono">{date}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="cb body-regular-400">
|
<div className="cb body-regular-400">
|
||||||
{body}
|
{body}
|
||||||
|
Loading…
Reference in New Issue
Block a user