@@ -675,13 +675,29 @@ const createInputSection = () => {
675675 type : "button" ,
676676 "aria-label" : "Send message" ,
677677 } ) ;
678- sendButton . innerHTML = `<svg width="20" height="20" viewBox="0 0 20 20" focusable="false" aria-hidden="true" role="img" class="spectrum-Icon spectrum-Icon--sizeXL"><path d="M18.6485 9.97369C18.6482 9.67918 18.4769 9.41125 18.2059 9.29075L4.05752 2.93301C3.80133 2.81769 3.50129 2.85602 3.28171 3.03141C3.06178 3.20784 2.95889 3.49165 3.01516 3.76752L4.28678 10.0082L3.06488 16.2386C3.0162 16.4854 3.09492 16.7382 3.27031 16.9136C3.29068 16.9339 3.31278 16.9533 3.33522 16.9716C3.55619 17.1456 3.85519 17.1822 4.11069 17.0662L18.2086 10.658C18.4773 10.5358 18.6489 10.2682 18.6485 9.97369ZM14.406 9.22735L5.66439 9.25398L4.77705 4.90103L14.406 9.22735ZM4.81711 15.0974L5.6694 10.7531L14.4323 10.7265L4.81711 15.0974Z" fill="#ffffff"/></svg>` ;
678+ sendButton . innerHTML = `<svg width="20" height="20" viewBox="0 0 20 20" focusable="false" aria-hidden="true" role="img" class="spectrum-Icon spectrum-Icon--sizeXL"><path d="M18.6485 9.97369C18.6482 9.67918 18.4769 9.41125 18.2059 9.29075L4.05752 2.93301C3.80133 2.81769 3.50129 2.85602 3.28171 3.03141C3.06178 3.20784 2.95889 3.49165 3.01516 3.76752L4.28678 10.0082L3.06488 16.2386C3.0162 16.4854 3.09492 16.7382 3.27031 16.9136C3.29068 16.9339 3.31278 16.9533 3.33522 16.9716C3.55619 17.1456 3.85519 17.1822 4.11069 17.0662L18.2086 10.658C18.4773 10.5358 18.6489 10.2682 18.6485 9.97369ZM14.406 9.22735L5.66439 9.25398L4.77705 4.90103L14.406 9.22735ZM4.81711 15.0974L5.6694 10.7531L14.4323 10.7265L4.81711 15.0974Z" fill="currentColor"/></svg>` ;
679+ sendButton . disabled = true ;
679680
680- inputSection . appendChild ( textarea ) ;
681+ const textareaWrapper = createTag ( "div" , { class : "chat-textarea-wrapper" } ) ;
682+ textareaWrapper . appendChild ( textarea ) ;
683+ textareaWrapper . appendChild ( sendButton ) ;
684+
685+ inputSection . appendChild ( textareaWrapper ) ;
681686 inputSection . appendChild ( disclaimerText ) ;
682- inputSection . appendChild ( sendButton ) ;
683687 ELEMENTS . CHAT_SEND_BUTTON = sendButton ;
684688 ELEMENTS . CHAT_TEXTAREA = textarea ;
689+
690+ sendButton . addEventListener ( "click" , handleUserQuery ) ;
691+ textarea . addEventListener ( "input" , ( ) => {
692+ sendButton . disabled = textarea . value . trim ( ) === "" ;
693+ } ) ;
694+ textarea . addEventListener ( "keydown" , ( e ) => {
695+ if ( e . key === "Enter" && ! e . shiftKey ) {
696+ e . preventDefault ( ) ;
697+ handleUserQuery ( ) ;
698+ }
699+ } ) ;
700+
685701 return inputSection ;
686702} ;
687703
@@ -820,6 +836,7 @@ const handleUserQuery = async (messageContentOverride) => {
820836 if ( ! messageContentOverride ) {
821837 messageContent = ELEMENTS . CHAT_TEXTAREA . value . trim ( ) ;
822838 ELEMENTS . CHAT_TEXTAREA . value = "" ;
839+ ELEMENTS . CHAT_TEXTAREA . dispatchEvent ( new Event ( "input" ) ) ;
823840 }
824841
825842 if ( ! messageContent ) {
@@ -1056,12 +1073,5 @@ export default async function decorate(block) {
10561073 minimizeChatWindow ,
10571074 ) ;
10581075 ELEMENTS . CHAT_WINDOW_CLOSE_BUTTON . addEventListener ( "click" , closeChatWindow ) ;
1059- ELEMENTS . CHAT_SEND_BUTTON . addEventListener ( "click" , handleUserQuery ) ;
1060- ELEMENTS . CHAT_TEXTAREA . addEventListener ( "keydown" , ( e ) => {
1061- if ( e . key === "Enter" && ! e . shiftKey ) {
1062- e . preventDefault ( ) ;
1063- handleUserQuery ( ) ;
1064- }
1065- } ) ;
10661076}
10671077// #endregion
0 commit comments