bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/screenreader-alert/component.tsx
Arthurk12 9947aa451e fix(screen-reader): add safeguards for adding alerts
Adds checks for the alert's text and DOM element before adding screen
reader alerts.
2024-05-02 23:06:55 +00:00

25 lines
754 B
TypeScript

import React, { useEffect } from 'react';
import { createPortal } from 'react-dom';
import { shiftAlert } from './service';
import { ScreenReaderAlert } from './queue';
const ARIA_ALERT_EXT_TIMEOUT = 15000;
interface Props {
olderAlert: ScreenReaderAlert | undefined;
}
const ScreenReaderAlert: React.FC<Props> = ({ olderAlert }) => {
useEffect(() => {
if (olderAlert) setTimeout(() => shiftAlert(), ARIA_ALERT_EXT_TIMEOUT);
}, [olderAlert?.id]);
const ariaAlertsElement = document.getElementById('aria-polite-alert');
return (olderAlert && olderAlert.text && ariaAlertsElement !== null)
? createPortal(olderAlert.text, document.getElementById('aria-polite-alert') as HTMLElement)
: null;
};
export default ScreenReaderAlert;