this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix textarea focus not working

+30 -18
+30 -18
src/components/compose.jsx
··· 96 96 })(); 97 97 }, []); 98 98 99 + const oninputTextarea = () => { 100 + if (!textareaRef.current) return; 101 + textareaRef.current.dispatchEvent(new Event('input')); 102 + }; 103 + const focusTextarea = () => { 104 + setTimeout(() => { 105 + textareaRef.current?.focus(); 106 + }, 100); 107 + }; 108 + 99 109 useEffect(() => { 100 110 if (replyToStatus) { 101 111 const { spoilerText, visibility, sensitive } = replyToStatus; 102 112 if (spoilerText && spoilerTextRef.current) { 103 113 spoilerTextRef.current.value = spoilerText; 104 - spoilerTextRef.current.focus(); 105 - } else { 106 - const mentions = new Set([ 107 - replyToStatus.account.acct, 108 - ...replyToStatus.mentions.map((m) => m.acct), 109 - ]); 110 - const allMentions = [...mentions].filter( 111 - (m) => m !== currentAccountInfo.acct, 112 - ); 113 - if (allMentions.length > 0) { 114 - textareaRef.current.value = `${allMentions 115 - .map((m) => `@${m}`) 116 - .join(' ')} `; 117 - textareaRef.current.dispatchEvent(new Event('input')); 118 - } 119 - textareaRef.current.focus(); 120 114 } 115 + const mentions = new Set([ 116 + replyToStatus.account.acct, 117 + ...replyToStatus.mentions.map((m) => m.acct), 118 + ]); 119 + const allMentions = [...mentions].filter( 120 + (m) => m !== currentAccountInfo.acct, 121 + ); 122 + if (allMentions.length > 0) { 123 + textareaRef.current.value = `${allMentions 124 + .map((m) => `@${m}`) 125 + .join(' ')} `; 126 + oninputTextarea(); 127 + } 128 + focusTextarea(); 121 129 setVisibility(visibility); 122 130 setSensitive(sensitive); 123 131 } ··· 136 144 expiresIn: poll?.expiresIn || expiresInFromExpiresAt(poll.expiresAt), 137 145 }; 138 146 textareaRef.current.value = status; 139 - textareaRef.current.dispatchEvent(new Event('input')); 147 + oninputTextarea(); 148 + focusTextarea(); 140 149 spoilerTextRef.current.value = spoilerText; 141 150 setVisibility(visibility); 142 151 setSensitive(sensitive); ··· 156 165 console.log({ statusSource }); 157 166 const { text, spoilerText } = statusSource; 158 167 textareaRef.current.value = text; 159 - textareaRef.current.dispatchEvent(new Event('input')); 160 168 textareaRef.current.dataset.source = text; 169 + oninputTextarea(); 170 + focusTextarea(); 161 171 spoilerTextRef.current.value = spoilerText; 162 172 setVisibility(visibility); 163 173 setSensitive(sensitive); ··· 170 180 setUIState('error'); 171 181 } 172 182 })(); 183 + } else { 184 + focusTextarea(); 173 185 } 174 186 }, [draftStatus, editStatus, replyToStatus]); 175 187