@@ -33,6 +33,11 @@ const inputContainerStyles = css({
3333
3434const textInputStyles = css ( {
3535 flexGrow : 1 ,
36+ // Override LeafyGreen input's padding to space for our robot.
37+ input : {
38+ paddingLeft : spacing [ 5 ] ,
39+ paddingRight : spacing [ 6 ] * 2 + spacing [ 2 ] ,
40+ } ,
3641} ) ;
3742
3843const errorSummaryContainer = css ( {
@@ -108,14 +113,10 @@ const buttonResetStyles = css({
108113 cursor : 'pointer' ,
109114} ) ;
110115
111- const closeAIButtonStyles = css (
112- buttonResetStyles ,
113- {
114- padding : spacing [ 1 ] ,
115- display : 'inline-flex' ,
116- } ,
117- focusRing
118- ) ;
116+ const closeAIButtonStyles = css ( buttonResetStyles , focusRing , {
117+ padding : spacing [ 1 ] ,
118+ position : 'absolute' ,
119+ } ) ;
119120
120121const closeText = 'Close AI Helper' ;
121122
@@ -177,6 +178,9 @@ function GenerativeAIInput({
177178 ( evt : React . KeyboardEvent < HTMLInputElement > ) => {
178179 if ( evt . key === 'Enter' ) {
179180 evt . preventDefault ( ) ;
181+ if ( ! aiPromptText ) {
182+ return ;
183+ }
180184 onSubmitText ( aiPromptText ) ;
181185 } else if ( evt . key === 'Escape' ) {
182186 isFetching ? onCancelRequest ( ) : onClose ( ) ;
@@ -232,22 +236,51 @@ function GenerativeAIInput({
232236 }
233237 onKeyDown = { onTextInputKeyDown }
234238 />
239+ < button
240+ className = { closeAIButtonStyles }
241+ data-testid = "close-ai-button"
242+ aria-label = { closeText }
243+ title = { closeText }
244+ onClick = { ( ) => onClose ( ) }
245+ >
246+ < RobotSVG />
247+ </ button >
235248 < div className = { floatingButtonsContainerStyles } >
236- { aiPromptText && (
237- < IconButton
238- aria-label = "Clear prompt"
239- onClick = { ( ) => onChangeAIPromptText ( '' ) }
240- data-testid = "ai-text-clear-prompt"
241- >
242- < Icon glyph = "X" />
243- </ IconButton >
249+ { isFetching ? (
250+ < div className = { loaderContainerStyles } >
251+ < SpinLoader />
252+ </ div >
253+ ) : showSuccess ? (
254+ < div className = { loaderContainerStyles } >
255+ < Icon
256+ className = {
257+ darkMode
258+ ? successIndicatorDarkModeStyles
259+ : successIndicatorLightModeStyles
260+ }
261+ glyph = "CheckmarkWithCircle"
262+ />
263+ </ div >
264+ ) : (
265+ < >
266+ { aiPromptText && (
267+ < IconButton
268+ aria-label = "Clear prompt"
269+ onClick = { ( ) => onChangeAIPromptText ( '' ) }
270+ data-testid = "ai-text-clear-prompt"
271+ >
272+ < Icon glyph = "X" />
273+ </ IconButton >
274+ ) }
275+ </ >
244276 ) }
245277 < Button
246278 size = "small"
247279 className = { cx (
248280 generateButtonStyles ,
249281 ! darkMode && generateButtonLightModeStyles
250282 ) }
283+ disabled = { ! aiPromptText }
251284 data-testid = "ai-generate-button"
252285 onClick = { ( ) =>
253286 isFetching ? onCancelRequest ( ) : onSubmitText ( aiPromptText )
@@ -274,32 +307,6 @@ function GenerativeAIInput({
274307 </ >
275308 ) }
276309 </ Button >
277- { isFetching ? (
278- < div className = { loaderContainerStyles } >
279- < SpinLoader />
280- </ div >
281- ) : showSuccess ? (
282- < div className = { loaderContainerStyles } >
283- < Icon
284- className = {
285- darkMode
286- ? successIndicatorDarkModeStyles
287- : successIndicatorLightModeStyles
288- }
289- glyph = "CheckmarkWithCircle"
290- />
291- </ div >
292- ) : (
293- < button
294- className = { closeAIButtonStyles }
295- data-testid = "close-ai-button"
296- aria-label = { closeText }
297- title = { closeText }
298- onClick = { ( ) => onClose ( ) }
299- >
300- { isFetching ? < SpinLoader /> : < RobotSVG /> }
301- </ button >
302- ) }
303310 </ div >
304311 </ div >
305312 { didSucceed && < AIFeedback onSubmitFeedback = { onSubmitFeedback } /> }
0 commit comments