Skip to content

Commit 9943c80

Browse files
feat: hide send button when stop button is rendered (#651)
* feat: hide send button when stop button is rendered * fix: tooltip alignment
1 parent 7dfc7a4 commit 9943c80

File tree

1 file changed

+32
-26
lines changed
  • packages/ai-chat/src/chat/components-legacy/input

1 file changed

+32
-26
lines changed

packages/ai-chat/src/chat/components-legacy/input/Input.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ function Input(props: InputProps, ref: Ref<InputFunctions>) {
250250
*/
251251
function onKeyDown(event: KeyboardEvent) {
252252
if (isEnterKey(event)) {
253-
if (disableSend || !enterKeyEnabled.current) {
253+
if (
254+
disableSend ||
255+
!enterKeyEnabled.current ||
256+
isStopStreamingButtonVisible
257+
) {
254258
// If sending is disabled, stop the field from inserting a newline into the field.
255259
event.preventDefault();
256260
} else {
@@ -502,11 +506,11 @@ function Input(props: InputProps, ref: Ref<InputFunctions>) {
502506
</div>
503507

504508
<div className="cds-aichat--input-container__send-button-container">
505-
{isStopStreamingButtonVisible && (
509+
{isStopStreamingButtonVisible ? (
506510
<StopStreamingButton
507511
label={input_stopResponse}
508512
disabled={isStopStreamingButtonDisabled}
509-
tooltipAlignment="top"
513+
tooltipAlignment={isRTL ? "top-left" : "top-right"}
510514
onClick={async () => {
511515
const { store } = serviceManager;
512516
store.dispatch(actions.setStopStreamingButtonDisabled(true));
@@ -515,32 +519,34 @@ function Input(props: InputProps, ref: Ref<InputFunctions>) {
515519
});
516520
// Also cancel the current message request to abort the signal
517521
await serviceManager.messageService.cancelCurrentMessageRequest();
522+
textAreaRef.current.takeFocus();
518523
}}
519524
/>
525+
) : (
526+
<Button
527+
className="cds-aichat--input-container__send-button"
528+
kind={BUTTON_KIND.GHOST}
529+
size={BUTTON_SIZE.SMALL}
530+
type={BUTTON_TYPE.BUTTON}
531+
onClick={send}
532+
aria-label={input_buttonLabel}
533+
disabled={showDisabledSend}
534+
tooltip-text={input_buttonLabel}
535+
tooltipAlignment={
536+
isRTL
537+
? BUTTON_TOOLTIP_ALIGNMENT.START
538+
: BUTTON_TOOLTIP_ALIGNMENT.END
539+
}
540+
tooltipPosition={BUTTON_TOOLTIP_POSITION.TOP}
541+
data-testid={PageObjectId.INPUT_SEND}
542+
>
543+
{hasValidInput ? (
544+
<SendFilled slot="icon" />
545+
) : (
546+
<Send slot="icon" />
547+
)}
548+
</Button>
520549
)}
521-
<Button
522-
className="cds-aichat--input-container__send-button"
523-
kind={BUTTON_KIND.GHOST}
524-
size={BUTTON_SIZE.SMALL}
525-
type={BUTTON_TYPE.BUTTON}
526-
onClick={send}
527-
aria-label={input_buttonLabel}
528-
disabled={showDisabledSend}
529-
tooltip-text={input_buttonLabel}
530-
tooltipAlignment={
531-
isRTL
532-
? BUTTON_TOOLTIP_ALIGNMENT.START
533-
: BUTTON_TOOLTIP_ALIGNMENT.END
534-
}
535-
tooltipPosition={BUTTON_TOOLTIP_POSITION.TOP}
536-
data-testid={PageObjectId.INPUT_SEND}
537-
>
538-
{hasValidInput ? (
539-
<SendFilled slot="icon" />
540-
) : (
541-
<Send slot="icon" />
542-
)}
543-
</Button>
544550
</div>
545551
</div>
546552
</div>

0 commit comments

Comments
 (0)