From bbee6d85d392e1689fbf83d015efbf9d43688cda Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 18 Aug 2018 20:53:46 +0200 Subject: [PATCH] Focus CW field when enabling it, focus compose textarea when disabling it Port 101f5544e18709e922b2a1e746957d6e2655f9d7 and d928aac40c4a7832cd523f3e737391641d762635 to glitch-soc --- .../glitch/features/composer/index.js | 21 +++++++++++++++++++ .../glitch/features/composer/spoiler/index.js | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/features/composer/index.js b/app/javascript/flavours/glitch/features/composer/index.js index e77d429bed..f312e9d598 100644 --- a/app/javascript/flavours/glitch/features/composer/index.js +++ b/app/javascript/flavours/glitch/features/composer/index.js @@ -237,6 +237,13 @@ const handlers = { this.textarea = textareaComponent.textarea; } }, + + // Sets a reference to the CW field. + handleRefSpoilerText (spoilerComponent) { + if (spoilerComponent) { + this.spoilerText = spoilerComponent.spoilerText; + } + } }; // The component. @@ -249,6 +256,7 @@ class Composer extends React.Component { // Instance variables. this.textarea = null; + this.spoilerText = null; } // Tells our state the composer has been mounted. @@ -277,6 +285,7 @@ class Composer extends React.Component { componentDidUpdate (prevProps) { const { textarea, + spoilerText, } = this; const { focusDate, @@ -308,6 +317,16 @@ class Composer extends React.Component { // Refocuses the textarea after submitting. } else if (textarea && prevProps.isSubmitting && !isSubmitting) { 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, handleSubmit, handleRefTextarea, + handleRefSpoilerText, } = this.handlers; const { acceptContentTypes, @@ -378,6 +398,7 @@ class Composer extends React.Component { onChange={handleChangeSpoiler} onSubmit={handleSubmit} text={spoilerText} + ref={handleRefSpoilerText} />