Merge pull request #20012 from prlanzarin/u27/fix/arthurk12-screenreader-crash

[2.7] fix(screen-reader): add safeguards for adding alerts
This commit is contained in:
Anton Georgiev 2024-04-12 15:33:28 -04:00 committed by GitHub
commit 10cb2f3875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,7 +9,10 @@ const ScreenReaderAlert = ({ olderAlert }) => {
if (olderAlert) setTimeout(() => removeAlert(olderAlert.id), ARIA_ALERT_EXT_TIMEOUT); if (olderAlert) setTimeout(() => removeAlert(olderAlert.id), ARIA_ALERT_EXT_TIMEOUT);
}, [olderAlert?.id]); }, [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; export default ScreenReaderAlert;