Merge pull request #20160 from prlanzarin/u30/fix/arthurk12-screenreader-crash

fix(screen-reader): add safeguards for adding alerts
This commit is contained in:
Anton Georgiev 2024-05-03 08:52:45 -04:00 committed by GitHub
commit 7c407567e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,9 @@ const ScreenReaderAlert: React.FC<Props> = ({ olderAlert }) => {
if (olderAlert) setTimeout(() => shiftAlert(), ARIA_ALERT_EXT_TIMEOUT);
}, [olderAlert?.id]);
return olderAlert
const ariaAlertsElement = document.getElementById('aria-polite-alert');
return (olderAlert && olderAlert.text && ariaAlertsElement !== null)
? createPortal(olderAlert.text, document.getElementById('aria-polite-alert') as HTMLElement)
: null;
};