Skip to content

Commit 3741773

Browse files
authored
Merge pull request #242 from rebeccaalpert/a11y-220
fix(Message): Make each Message a section
2 parents 3234dc3 + da68c38 commit 3741773

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/module/src/Message/Message.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,16 @@ export const Message: React.FunctionComponent<MessageProps> = ({
8181
onAttachmentClose && attachmentId && onAttachmentClose(attachmentId);
8282
};
8383

84+
// Keep timestamps consistent between Timestamp component and aria-label
85+
const date = new Date();
86+
const dateString = timestamp ?? `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
87+
8488
return (
85-
<div className={`pf-chatbot__message pf-chatbot__message--${role}`} {...props}>
89+
<section
90+
aria-label={`Message from ${role} - ${dateString}`}
91+
className={`pf-chatbot__message pf-chatbot__message--${role}`}
92+
{...props}
93+
>
8694
{/* We are using an empty alt tag intentionally in order to reduce noise on screen readers */}
8795
<Avatar src={avatar ?? DEFAULTS[role].avatar} alt="" />
8896
<div className="pf-chatbot__message-contents">
@@ -93,7 +101,7 @@ export const Message: React.FunctionComponent<MessageProps> = ({
93101
AI
94102
</Label>
95103
)}
96-
<Timestamp>{timestamp}</Timestamp>
104+
<Timestamp date={date}>{timestamp}</Timestamp>
97105
</div>
98106
<div className="pf-chatbot__message-response">
99107
<div className="pf-chatbot__message-and-actions">
@@ -114,7 +122,7 @@ export const Message: React.FunctionComponent<MessageProps> = ({
114122
)}
115123
</div>
116124
</div>
117-
</div>
125+
</section>
118126
);
119127
};
120128

0 commit comments

Comments
 (0)