mirror of
https://github.com/owncast/owncast.git
synced 2024-11-25 06:12:23 +03:00
Fixes for aria-live bugs (#3694)
* make the aria-live text adhere to the last message's username * Wrap lastMessage in an Interweave to handle pre-encoded characters properly --------- Co-authored-by: Muaz Ahmad <mahmad2000@protonmail.com>
This commit is contained in:
parent
1d3e52d2bb
commit
5a145eb407
1 changed files with 11 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { Virtuoso } from 'react-virtuoso';
|
import { Virtuoso } from 'react-virtuoso';
|
||||||
import { useState, useMemo, useRef, CSSProperties, FC, useEffect } from 'react';
|
import { useState, useMemo, useRef, CSSProperties, FC, useEffect } from 'react';
|
||||||
import { ErrorBoundary } from 'react-error-boundary';
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
|
import { Interweave } from 'interweave';
|
||||||
import {
|
import {
|
||||||
ConnectedClientInfoEvent,
|
ConnectedClientInfoEvent,
|
||||||
FediverseEvent,
|
FediverseEvent,
|
||||||
|
@ -320,8 +321,15 @@ export const ChatContainer: FC<ChatContainerProps> = ({
|
||||||
// Retrieve, clean, and attach username to newest chat message to be read out by screenreader
|
// Retrieve, clean, and attach username to newest chat message to be read out by screenreader
|
||||||
function getLastMessage() {
|
function getLastMessage() {
|
||||||
if (messages.length > 0 && typeof messages[messages.length - 1].body !== 'undefined') {
|
if (messages.length > 0 && typeof messages[messages.length - 1].body !== 'undefined') {
|
||||||
const message = messages[messages.length - 1].body.replace(/(<([^>]+)>)/gi, '');
|
const lastMessage = messages[messages.length - 1];
|
||||||
const stringToRead = `${usernameToHighlight} said ${message}`;
|
const message = lastMessage.body.replace(/(<([^>]+)>)/gi, '');
|
||||||
|
let stringToRead = '';
|
||||||
|
if (typeof lastMessage.user !== 'undefined') {
|
||||||
|
const username = lastMessage.user.displayName;
|
||||||
|
stringToRead = `${username} said ${message}`;
|
||||||
|
} else {
|
||||||
|
stringToRead = `System message: ${message}`;
|
||||||
|
}
|
||||||
return stringToRead;
|
return stringToRead;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
@ -364,7 +372,7 @@ export const ChatContainer: FC<ChatContainerProps> = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className={styles.chatAccessibilityHidden} aria-live="polite">
|
<span className={styles.chatAccessibilityHidden} aria-live="polite">
|
||||||
{lastMessage}
|
<Interweave content={lastMessage} />
|
||||||
</span>
|
</span>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue