Skip to content

Commit

Permalink
fix(MessageBar): Show SpeechRecognition output
Browse files Browse the repository at this point in the history
With swap to new textarea, I missed adding the SpeechRecognition output. This should put the message content in. I briefly explored a controlled approach, but we have to deal with ranges and selections to make the cursor work. The approach I tried broke whitespace on Firefox and also hitting return + shift everywhere. This should let us keep using the native browser behavior, while adding the message updates.
  • Loading branch information
rebeccaalpert committed Dec 3, 2024
1 parent 3552c88 commit 108946f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/module/src/MessageBar/MessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
attachMenuProps?.onAttachMenuToggleClick();
};

const handleSpeechRecognition = (message) => {
setMessage(message);
const textarea = textareaRef.current;
if (textarea) {
textarea.focus();
textarea.textContent = DOMPurify.sanitize(message);
}
};

const renderButtons = () => {
if (hasStopButton && handleStopButton) {
return (
Expand Down Expand Up @@ -173,7 +182,7 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
<MicrophoneButton
isListening={isListeningMessage}
onIsListeningChange={setIsListeningMessage}
onSpeechRecognition={setMessage}
onSpeechRecognition={handleSpeechRecognition}
tooltipContent={buttonProps?.microphone?.tooltipContent}
{...buttonProps?.microphone?.props}
/>
Expand Down Expand Up @@ -216,7 +225,7 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
ref={textareaRef}
onKeyDown={handleKeyDown}
{...props}
></div>
/>
</div>
<div className="pf-chatbot__message-bar-actions">{renderButtons()}</div>
</>
Expand Down

0 comments on commit 108946f

Please sign in to comment.