@@ -26,37 +26,41 @@ interface UseComposerSubmissionProps {
2626
2727export function useComposerSubmission ( { scope, mode } : UseComposerSubmissionProps ) {
2828 const active = useRef < PendingComposerSubmission | null > ( null )
29- const focusBeforeSend = useRef < HTMLElement | null > ( null )
29+ const focusAfterSend = useRef < HTMLTextAreaElement | null > ( null )
3030 const [ pending , setPending ] = useState ( false )
3131
3232 useLayoutEffect ( ( ) => {
3333 setPending ( false )
3434 return ( ) => {
3535 active . current = null
36- focusBeforeSend . current = null
36+ focusAfterSend . current = null
3737 }
3838 } , [ scope , mode ] )
3939
4040 useLayoutEffect ( ( ) => {
4141 if ( pending ) return
42- const previous = focusBeforeSend . current
43- focusBeforeSend . current = null
44- if ( previous ?. isConnected && document . hasFocus ( ) && document . activeElement === document . body ) {
45- previous . focus ( { preventScroll : true } )
42+ const input = focusAfterSend . current
43+ focusAfterSend . current = null
44+ if ( input ?. isConnected && document . hasFocus ( ) && document . activeElement === document . body ) {
45+ input . focus ( { preventScroll : true } )
4646 }
4747 } , [ pending ] )
4848
4949 const accept = useCallback (
50- ( submit : ( ) => unknown , clear : ( ) => void , unchanged : ( ) => boolean ) => {
50+ (
51+ submit : ( ) => unknown ,
52+ clear : ( ) => void ,
53+ unchanged : ( ) => boolean ,
54+ input : HTMLTextAreaElement | null
55+ ) => {
5156 if ( active . current ) return
5257 const result = submit ( )
5358 if ( ! ( result instanceof PendingComposerSubmission ) ) {
5459 if ( result !== false ) clear ( )
5560 return
5661 }
5762 active . current = result
58- focusBeforeSend . current =
59- document . activeElement instanceof HTMLElement ? document . activeElement : null
63+ focusAfterSend . current = input
6064 setPending ( true )
6165 void result . ready
6266 . then ( ( commit ) => {
0 commit comments