Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/module/src/MessageBar/MessageBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ describe('Message bar', () => {
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(expect.any(Object), 'A');
});
it('can use specified placeholder text', async () => {
render(<MessageBar onSendMessage={jest.fn} placeholder="test placeholder" />);
const input = screen.getByRole('textbox', { name: /test placeholder/i });
await userEvent.type(input, 'Hello world');
expect(input).toHaveTextContent('Hello world');
});

// Send button
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -304,6 +310,13 @@ describe('Message bar', () => {
await userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
expect(screen.getByRole('tooltip', { name: 'Not currently listening' })).toBeTruthy();
});
it('can customize the listening placeholder', async () => {
mockSpeechRecognition();
render(<MessageBar onSendMessage={jest.fn} hasMicrophoneButton listeningText="I am listening" />);
await userEvent.click(screen.getByRole('button', { name: 'Microphone button' }));
const input = screen.getByRole('textbox', { name: /I am listening/i });
expect(input).toBeTruthy();
});
it('can handle buttonProps props appropriately for microphone', async () => {
mockSpeechRecognition();
render(
Expand Down
10 changes: 8 additions & 2 deletions packages/module/src/MessageBar/MessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ export interface MessageBarProps extends TextAreaProps {
className?: string;
/** Flag to always to show the send button. By default send button is shown when there is a message in the input field */
alwayShowSendButton?: boolean;
/** Placeholder for message input */
placeholder?: string;
/** Flag to disable/enable the Attach button */
hasAttachButton?: boolean;
/** Flag to enable the Microphone button */
hasMicrophoneButton?: boolean;
/** Placeholder text when listening */
listeningText?: string;
/** Flag to enable the Stop button, used for streaming content */
hasStopButton?: boolean;
/** Callback function for when stop button is clicked */
Expand Down Expand Up @@ -78,8 +82,10 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
onSendMessage,
className,
alwayShowSendButton,
placeholder = 'Send a message...',
hasAttachButton = true,
hasMicrophoneButton,
listeningText = 'Listening',
handleAttach,
attachMenuProps,
isSendButtonDisabled,
Expand Down Expand Up @@ -322,8 +328,8 @@ export const MessageBar: React.FunctionComponent<MessageBarProps> = ({
className="pf-chatbot__message-textarea"
value={message}
onChange={handleChange}
aria-label={isListeningMessage ? 'Listening' : 'Send a message...'}
placeholder={isListeningMessage ? 'Listening' : 'Send a message...'}
aria-label={isListeningMessage ? listeningText : placeholder}
placeholder={isListeningMessage ? listeningText : placeholder}
ref={textareaRef}
onKeyDown={handleKeyDown}
{...props}
Expand Down
Loading