Focus CW field when enabling it, focus compose textarea when disabling it
Portpull/653/heada99179d31f
and09147186b7
to glitch-soc
parent
484b9314e3
commit
432f6b88b0
|
@ -237,6 +237,13 @@ const handlers = {
|
||||||
this.textarea = textareaComponent.textarea;
|
this.textarea = textareaComponent.textarea;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Sets a reference to the CW field.
|
||||||
|
handleRefSpoilerText (spoilerComponent) {
|
||||||
|
if (spoilerComponent) {
|
||||||
|
this.spoilerText = spoilerComponent.spoilerText;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The component.
|
// The component.
|
||||||
|
@ -249,6 +256,7 @@ class Composer extends React.Component {
|
||||||
|
|
||||||
// Instance variables.
|
// Instance variables.
|
||||||
this.textarea = null;
|
this.textarea = null;
|
||||||
|
this.spoilerText = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tells our state the composer has been mounted.
|
// Tells our state the composer has been mounted.
|
||||||
|
@ -277,6 +285,7 @@ class Composer extends React.Component {
|
||||||
componentDidUpdate (prevProps) {
|
componentDidUpdate (prevProps) {
|
||||||
const {
|
const {
|
||||||
textarea,
|
textarea,
|
||||||
|
spoilerText,
|
||||||
} = this;
|
} = this;
|
||||||
const {
|
const {
|
||||||
focusDate,
|
focusDate,
|
||||||
|
@ -308,6 +317,16 @@ class Composer extends React.Component {
|
||||||
// Refocuses the textarea after submitting.
|
// Refocuses the textarea after submitting.
|
||||||
} else if (textarea && prevProps.isSubmitting && !isSubmitting) {
|
} else if (textarea && prevProps.isSubmitting && !isSubmitting) {
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
|
} else if (this.props.spoiler !== prevProps.spoiler) {
|
||||||
|
if (this.props.spoiler) {
|
||||||
|
if (spoilerText) {
|
||||||
|
spoilerText.focus();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (textarea) {
|
||||||
|
textarea.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +338,7 @@ class Composer extends React.Component {
|
||||||
handleSelect,
|
handleSelect,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
handleRefTextarea,
|
handleRefTextarea,
|
||||||
|
handleRefSpoilerText,
|
||||||
} = this.handlers;
|
} = this.handlers;
|
||||||
const {
|
const {
|
||||||
acceptContentTypes,
|
acceptContentTypes,
|
||||||
|
@ -378,6 +398,7 @@ class Composer extends React.Component {
|
||||||
onChange={handleChangeSpoiler}
|
onChange={handleChangeSpoiler}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
text={spoilerText}
|
text={spoilerText}
|
||||||
|
ref={handleRefSpoilerText}
|
||||||
/>
|
/>
|
||||||
<ComposerTextarea
|
<ComposerTextarea
|
||||||
advancedOptions={advancedOptions}
|
advancedOptions={advancedOptions}
|
||||||
|
|
|
@ -33,6 +33,10 @@ const handlers = {
|
||||||
onSubmit();
|
onSubmit();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleRefSpoilerText (spoilerText) {
|
||||||
|
this.spoilerText = spoilerText;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// The component.
|
// The component.
|
||||||
|
@ -46,7 +50,7 @@ export default class ComposerSpoiler extends React.PureComponent {
|
||||||
|
|
||||||
// Rendering.
|
// Rendering.
|
||||||
render () {
|
render () {
|
||||||
const { handleKeyDown } = this.handlers;
|
const { handleKeyDown, handleRefSpoilerText } = this.handlers;
|
||||||
const {
|
const {
|
||||||
hidden,
|
hidden,
|
||||||
intl,
|
intl,
|
||||||
|
@ -68,6 +72,7 @@ export default class ComposerSpoiler extends React.PureComponent {
|
||||||
placeholder={intl.formatMessage(messages.placeholder)}
|
placeholder={intl.formatMessage(messages.placeholder)}
|
||||||
type='text'
|
type='text'
|
||||||
value={text}
|
value={text}
|
||||||
|
ref={handleRefSpoilerText}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue