Skip to content

Commit 96bfc94

Browse files
author
Kateryna Kodonenko
committed
Focus on text input field
1 parent a13bd73 commit 96bfc94

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

packages/help-center/src/components/help-center-container.tsx

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,6 @@ const HelpCenterContainer: React.FC< Container > = ( {
6363

6464
const cardMergeRefs = useMergeRefs( [ nodeRef, focusReturnRef ] );
6565

66-
// Keep focus within the help center when entering `Zendesk messaging`
67-
useEffect( () => {
68-
const helpCenter = nodeRef.current;
69-
if ( ! helpCenter ) {
70-
return;
71-
}
72-
73-
helpCenter.setAttribute( 'tabindex', '-1' );
74-
75-
// Focus the chat container when it appears
76-
const observer = new MutationObserver( ( mutations ) => {
77-
for ( const mutation of mutations ) {
78-
if ( mutation.type === 'childList' ) {
79-
const chatContainer = document.querySelector( '.chatbox' ) as HTMLElement;
80-
if ( chatContainer ) {
81-
chatContainer.setAttribute( 'tabindex', '-1' );
82-
chatContainer.focus();
83-
observer.disconnect();
84-
break;
85-
}
86-
}
87-
}
88-
} );
89-
90-
observer.observe( helpCenter, { childList: true, subtree: true } );
91-
92-
return () => {
93-
observer.disconnect();
94-
};
95-
}, [ show, isMinimized ] );
96-
9766
const shouldCloseOnEscapeRef = useRef( false );
9867

9968
shouldCloseOnEscapeRef.current = !! show && ! hidden && ! isMinimized;

packages/odie-client/src/components/send-message-input/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@automattic/zendesk-client';
77
import { DropZone, Spinner } from '@wordpress/components';
88
import { useSelect } from '@wordpress/data';
9-
import { useCallback, useRef, useState } from '@wordpress/element';
9+
import { useCallback, useRef, useState, useEffect } from '@wordpress/element';
1010
import { __ } from '@wordpress/i18n';
1111
import clsx from 'clsx';
1212
import { SendMessageIcon } from '../../assets/send-message-icon';
@@ -65,9 +65,17 @@ export const OdieSendMessageButton = () => {
6565
false;
6666
const sendMessage = useSendChatMessage();
6767
const isChatBusy = chat.status === 'loading' || chat.status === 'sending';
68+
const isInitialLoading = chat.status === 'loading';
6869
const [ isMessageSizeValid, setIsMessageSizeValid ] = useState( true );
6970
const [ submitDisabled, setSubmitDisabled ] = useState( true );
7071

72+
// Focus input when chat is ready
73+
useEffect( () => {
74+
if ( ! isInitialLoading ) {
75+
inputRef.current?.focus();
76+
}
77+
}, [ isInitialLoading ] );
78+
7179
const { data: authData } = useAuthenticateZendeskMessaging(
7280
isUserEligibleForPaidSupport,
7381
'messenger'

0 commit comments

Comments
 (0)