Skip to content

Commit

Permalink
fix(Message): Make each Message a section
Browse files Browse the repository at this point in the history
This makes it a little easier to navigate with screenreaders.
  • Loading branch information
rebeccaalpert committed Oct 14, 2024
1 parent e0c7ea7 commit da68c38
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/module/src/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ export const Message: React.FunctionComponent<MessageProps> = ({
onAttachmentClose && attachmentId && onAttachmentClose(attachmentId);
};

// Keep timestamps consistent between Timestamp component and aria-label
const date = new Date();
const dateString = timestamp ?? `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;

return (
<div className={`pf-chatbot__message pf-chatbot__message--${role}`} {...props}>
<section
aria-label={`Message from ${role} - ${dateString}`}
className={`pf-chatbot__message pf-chatbot__message--${role}`}
{...props}
>
{/* We are using an empty alt tag intentionally in order to reduce noise on screen readers */}
<Avatar src={avatar ?? DEFAULTS[role].avatar} alt="" />
<div className="pf-chatbot__message-contents">
Expand All @@ -93,7 +101,7 @@ export const Message: React.FunctionComponent<MessageProps> = ({
AI
</Label>
)}
<Timestamp>{timestamp}</Timestamp>
<Timestamp date={date}>{timestamp}</Timestamp>
</div>
<div className="pf-chatbot__message-response">
<div className="pf-chatbot__message-and-actions">
Expand All @@ -114,7 +122,7 @@ export const Message: React.FunctionComponent<MessageProps> = ({
)}
</div>
</div>
</div>
</section>
);
};

Expand Down

0 comments on commit da68c38

Please sign in to comment.