diff --git a/packages/jupyter-chat/src/components/chat-input.tsx b/packages/jupyter-chat/src/components/chat-input.tsx index 40e27b9b..41a15b41 100644 --- a/packages/jupyter-chat/src/components/chat-input.tsx +++ b/packages/jupyter-chat/src/components/chat-input.tsx @@ -78,6 +78,8 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element { // controls whether the slash command autocomplete is open const [open, setOpen] = useState(false); + const inputExists = !!input.trim(); + /** * Effect: fetch the list of available autocomplete commands. */ @@ -130,16 +132,22 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element { return; } - // do not send the message if the user was selecting a suggested command from the + // Do not send the message if the user was selecting a suggested command from the // Autocomplete component. if (highlighted) { return; } + // Do not send empty messages, and avoid adding new line in empty message. + if (!inputExists) { + event.stopPropagation(); + event.preventDefault(); + return; + } + if ( - event.key === 'Enter' && - ((sendWithShiftEnter && event.shiftKey) || - (!sendWithShiftEnter && !event.shiftKey)) + (sendWithShiftEnter && event.shiftKey) || + (!sendWithShiftEnter && !event.shiftKey) ) { onSend(); event.stopPropagation(); @@ -224,16 +232,11 @@ ${selection.source} ...params.InputProps, endAdornment: ( - {props.onCancel && ( - 0} - onCancel={onCancel} - /> - )} + {props.onCancel && } 0} + inputExists={inputExists} onSend={onSend} hideIncludeSelection={hideIncludeSelection} hasButtonOnLeft={!!props.onCancel} diff --git a/packages/jupyter-chat/src/components/input/cancel-button.tsx b/packages/jupyter-chat/src/components/input/cancel-button.tsx index f38dee6b..22fd806d 100644 --- a/packages/jupyter-chat/src/components/input/cancel-button.tsx +++ b/packages/jupyter-chat/src/components/input/cancel-button.tsx @@ -13,7 +13,6 @@ const CANCEL_BUTTON_CLASS = 'jp-chat-cancel-button'; * The cancel button props. */ export type CancelButtonProps = { - inputExists: boolean; onCancel: () => void; }; @@ -22,11 +21,9 @@ export type CancelButtonProps = { */ export function CancelButton(props: CancelButtonProps): JSX.Element { const tooltip = 'Cancel edition'; - const disabled = !props.inputExists; return (