From 6cb0e914ab9fd38e16ac943317a6b8809bb5b645 Mon Sep 17 00:00:00 2001 From: Arthurk12 Date: Thu, 11 Apr 2024 14:34:41 -0300 Subject: [PATCH] fix(screen-reader): add safeguards for adding alerts Adds checks for the alert's text and DOM element before adding screen reader alerts. --- .../imports/ui/components/screenreader-alert/component.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bigbluebutton-html5/imports/ui/components/screenreader-alert/component.jsx b/bigbluebutton-html5/imports/ui/components/screenreader-alert/component.jsx index f4d5a2c5b6..9e9947a89f 100644 --- a/bigbluebutton-html5/imports/ui/components/screenreader-alert/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/screenreader-alert/component.jsx @@ -9,7 +9,10 @@ const ScreenReaderAlert = ({ olderAlert }) => { if (olderAlert) setTimeout(() => removeAlert(olderAlert.id), ARIA_ALERT_EXT_TIMEOUT); }, [olderAlert?.id]); - return olderAlert ? createPortal(olderAlert.text, document.getElementById('aria-polite-alert')) : null; + const ariaAlertsElement = document.getElementById('aria-polite-alert'); + const shouldAddAlert = olderAlert && olderAlert.text && ariaAlertsElement !== null; + + return shouldAddAlert ? createPortal(olderAlert.text, ariaAlertsElement) : null; }; export default ScreenReaderAlert;