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:
commit
10cb2f3875
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user