Closes #61
This commit is contained in:
parent
3c7682a84c
commit
ecb585c11b
|
@ -191,8 +191,9 @@ const Editor = props => {
|
||||||
<div ref={element} className={dragged ? 'r6o-editor dragged' : 'r6o-editor'}>
|
<div ref={element} className={dragged ? 'r6o-editor dragged' : 'r6o-editor'}>
|
||||||
<div className="r6o-arrow" />
|
<div className="r6o-arrow" />
|
||||||
<div className="r6o-editor-inner">
|
<div className="r6o-editor-inner">
|
||||||
{widgets.map(widget =>
|
{widgets.map((widget, idx) =>
|
||||||
React.cloneElement(widget, {
|
React.cloneElement(widget, {
|
||||||
|
focus: idx === 0,
|
||||||
annotation : currentAnnotation,
|
annotation : currentAnnotation,
|
||||||
readOnly : props.readOnly,
|
readOnly : props.readOnly,
|
||||||
env: props.env,
|
env: props.env,
|
||||||
|
|
|
@ -14,8 +14,13 @@ export default class Autocomplete extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.props.initialValue && this.element.current)
|
if (this.element.current) {
|
||||||
this.element.current.querySelector('input').value = this.props.initialValue;
|
if (this.props.initialValue)
|
||||||
|
this.element.current.querySelector('input').value = this.props.initialValue;
|
||||||
|
|
||||||
|
if (this.props.focus)
|
||||||
|
this.element.current.querySelector('input').focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onInputValueChange = ({ inputValue }) => {
|
onInputValueChange = ({ inputValue }) => {
|
||||||
|
|
|
@ -60,6 +60,7 @@ const getDraftReply = (existingDraft, isReply) => {
|
||||||
* Renders a list of comment bodies, followed by a 'reply' field.
|
* Renders a list of comment bodies, followed by a 'reply' field.
|
||||||
*/
|
*/
|
||||||
const CommentWidget = props => {
|
const CommentWidget = props => {
|
||||||
|
|
||||||
// All comments
|
// All comments
|
||||||
const all = props.annotation ?
|
const all = props.annotation ?
|
||||||
props.annotation.bodies.filter(body => isComment(body, props.purposeSelector)) : [];
|
props.annotation.bodies.filter(body => isComment(body, props.purposeSelector)) : [];
|
||||||
|
@ -103,6 +104,7 @@ const CommentWidget = props => {
|
||||||
{ !props.readOnly && props.annotation &&
|
{ !props.readOnly && props.annotation &&
|
||||||
<div className="r6o-widget comment editable">
|
<div className="r6o-widget comment editable">
|
||||||
<TextEntryField
|
<TextEntryField
|
||||||
|
focus={props.focus}
|
||||||
content={draftReply.value}
|
content={draftReply.value}
|
||||||
editable={true}
|
editable={true}
|
||||||
placeholder={comments.length > 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')}
|
placeholder={comments.length > 0 ? i18n.t('Add a reply...') : i18n.t('Add a comment...')}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component, createRef } from 'react';
|
||||||
import TextareaAutosize from 'react-autosize-textarea';
|
import TextareaAutosize from 'react-autosize-textarea';
|
||||||
import i18n from '../../../i18n';
|
import i18n from '../../../i18n';
|
||||||
|
|
||||||
|
@ -7,21 +7,27 @@ import i18n from '../../../i18n';
|
||||||
*/
|
*/
|
||||||
export default class TextEntryField extends Component {
|
export default class TextEntryField extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.element = createRef();
|
||||||
|
}
|
||||||
|
|
||||||
// CTRL+Enter functions as Ok
|
// CTRL+Enter functions as Ok
|
||||||
onKeyDown = evt => {
|
onKeyDown = evt => {
|
||||||
if (evt.which === 13 && evt.ctrlKey)
|
if (evt.which === 13 && evt.ctrlKey)
|
||||||
this.props.onSaveAndClose();
|
this.props.onSaveAndClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focus on render
|
componentDidMount() {
|
||||||
onRender = ref => {
|
if (this.props.focus && this.element.current)
|
||||||
// Note: we could use this to set automatic focus (but leave this out for now)
|
this.element.current.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<TextareaAutosize
|
<TextareaAutosize
|
||||||
ref={this.onRender}
|
ref={this.element}
|
||||||
className={this.props.editable ? 'r6o-editable-text r6o-nodrag' : 'r6o-editable-text'}
|
className={this.props.editable ? 'r6o-editable-text r6o-nodrag' : 'r6o-editable-text'}
|
||||||
value={this.props.content}
|
value={this.props.content}
|
||||||
placeholder={this.props.placeholder || i18n.t('Add a comment...')}
|
placeholder={this.props.placeholder || i18n.t('Add a comment...')}
|
||||||
|
|
|
@ -82,6 +82,7 @@ const TagWidget = props => {
|
||||||
|
|
||||||
{!props.readOnly &&
|
{!props.readOnly &&
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
|
focus={props.focus}
|
||||||
placeholder={i18n.t('Add tag...')}
|
placeholder={i18n.t('Add tag...')}
|
||||||
initialValue={draftTag.value}
|
initialValue={draftTag.value}
|
||||||
onChange={onDraftChange}
|
onChange={onDraftChange}
|
||||||
|
|
Loading…
Reference in New Issue