Render <FormErrorMessage> at render time instead of dispatch time
See original GitHub issue🐛 Bug report
The <FormErrorMessage>
-component only adds the error message to the DOM at message dispatch time instead of at site render time. This causes some screen readers to not see the aria-live attributes present when they appear. I tested this using VoiceOver and NVDA, the aria-live messages worked great in VoiceOver but failed using NVDA. I do not have access to test this on JAWS.
I have encountered this issue before, some assistive technologies fail to detect aria-live regions that are added to a page dynamically.
MDN tells us
"Including an aria-live attribute or a specialized live region role (such as role="alert") on the element you want to announce changes to works as long as you add the attribute before the changes occur — either in the original markup, or dynamically using JavaScript."
. I’m not sure what they mean by “dynamically” but they state that the element should have the attribute before the change occours.
I found some more info on this here https://almerosteyn.com/2017/09/aria-live-regions-in-react
💥 Steps to reproduce
Create a form Have your errors in <FormErrorMessage/ > Form error messages with aria-live are not available in the DOM until they are dispatched.
💻 Link to reproduction
🧐 Expected behavior
Form error messages are loaded into the DOM at site render time and visually hidden using CSS and if needed aria-hidden (depending on how this is solved)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (1 by maintainers)
Top GitHub Comments
@with-heart Yeh, multiple live regions don’t play well with each other. Ideally <FormErrorMessage> should not use
aria-live
and instead be associated to the element witharia-describedby
. On top of this, there should be a separate live region component with all the errors to be used in one place for the entire form. This component needs to be permanently mounted so that screen readers are aware of any changes.Hi! This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs within 5 days. Thank you for your contributions.