Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

State-changed events modified to be in aria live region (#3469)

Riya Bhatia2e557aa6f75a
diff --git a/web/components/chat/ChatContainer/ChatContainer.module.scss b/web/components/chat/ChatContainer/ChatContainer.module.scss
index b44aab381d..49678f5a47 100644
--- a/web/components/chat/ChatContainer/ChatContainer.module.scss
+++ b/web/components/chat/ChatContainer/ChatContainer.module.scss
@@ -71,3 +71,12 @@
transform: translateY(0);
}
}
+
+.chatAccessibilityHidden {
+ top:0;
+ left:-2px;
+ width:1px;
+ height:1px;
+ position:absolute;
+ overflow:hidden;
+}
diff --git a/web/components/chat/ChatContainer/ChatContainer.tsx b/web/components/chat/ChatContainer/ChatContainer.tsx
index 6b5ce9467f..06a1413b48 100644
--- a/web/components/chat/ChatContainer/ChatContainer.tsx
+++ b/web/components/chat/ChatContainer/ChatContainer.tsx
@@ -317,6 +317,17 @@ export const ChatContainer: FC<ChatContainerProps> = ({
}
}
+ // Retrieve, clean, and attach username to newest chat message to be read out by screenreader
+ function getLastMessage() {
+ if (messages.length > 0 && typeof messages[messages.length - 1].body !== 'undefined') {
+ const message = messages[messages.length - 1].body.replace(/(<([^>]+)>)/gi, '');
+ const stringToRead = `${usernameToHighlight} said ${message}`;
+ return stringToRead;
+ }
+ return '';
+ }
+ const lastMessage = getLastMessage();
+
if (resizeWindowCallback) window.removeEventListener('resize', resizeWindowCallback);
if (desktop) {
window.addEventListener('resize', resize);
@@ -337,6 +348,7 @@ export const ChatContainer: FC<ChatContainerProps> = ({
)}
>
<div
+ aria-live="off"
id="chat-container"
className={styles.chatContainer}
style={desktop && { width: `${defaultChatWidth}px` }}
@@ -351,6 +363,9 @@ export const ChatContainer: FC<ChatContainerProps> = ({
<div className={styles.resizeHandle} onMouseDown={startDrag} role="presentation" />
)}
</div>
+ <span className={styles.chatAccessibilityHidden} aria-live="polite">
+ {lastMessage}
+ </span>
</ErrorBoundary>
);
};