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
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ _Italic text, formatted with single underscores_
content="This bot has a square avatar. You can further customize the avatar by applying an additional class or passing [PatternFly avatar props](/components/avatar) to the `<Message>` component via `avatarProps`."
hasRoundAvatar={false}
/>
<Message name="Bot" role="bot" content="This is a message from a bot with no avatar." />
<Select
id="single-select"
isOpen={isOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ _Italic text, formatted with single underscores_
avatar={userAvatar}
avatarProps={{ isBordered: true }}
/>
<Message name="User" role="user" content="This is a user message with no avatar" />
<Message
name="User"
role="user"
Expand Down
4 changes: 4 additions & 0 deletions packages/module/src/Message/Message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ describe('Message', () => {
render(<Message avatar="./testImg" role="bot" name="Bot" content="Hi" />);
expect(screen.getByRole('img')).toHaveAttribute('src', './testImg');
});
it('should not render avatar if no avatar prop is passed', () => {
render(<Message role="bot" name="Bot" content="Hi" />);
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});
it('should render botWord correctly', () => {
render(<Message avatar="./img" role="bot" name="Bot" content="Hi" botWord="人工知能" />);
expect(screen.getByText('Bot')).toBeTruthy();
Expand Down
16 changes: 9 additions & 7 deletions packages/module/src/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface MessageProps extends Omit<HTMLProps<HTMLDivElement>, 'role'> {
/** Name of the user */
name?: string;
/** Avatar src for the user */
avatar: string;
avatar?: string;
/** Timestamp for the message */
timestamp?: string;
/** Set this to true if message is being loaded */
Expand Down Expand Up @@ -459,12 +459,14 @@ export const MessageBase: FunctionComponent<MessageProps> = ({
{...props}
>
{/* We are using an empty alt tag intentionally in order to reduce noise on screen readers */}
<Avatar
className={`pf-chatbot__message-avatar ${hasRoundAvatar ? 'pf-chatbot__message-avatar--round' : ''} ${avatarClassName ? avatarClassName : ''}`}
src={avatar}
alt=""
{...avatarProps}
/>
{avatar && (
<Avatar
className={`pf-chatbot__message-avatar ${hasRoundAvatar ? 'pf-chatbot__message-avatar--round' : ''} ${avatarClassName ? avatarClassName : ''}`}
src={avatar}
alt=""
{...avatarProps}
/>
)}
<div className="pf-chatbot__message-contents">
<div className="pf-chatbot__message-meta">
{name && (
Expand Down
Loading