fix(screen-reader): add safeguards for adding alerts
Adds checks for the alert's text and DOM element before adding screen reader alerts.
This commit is contained in:
parent
fcbfcb1bbc
commit
6cb0e914ab
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user