Fix Modal aria hidden warning #480
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #476
Problem
Bit of a complex one; aria-hidden wasn't being set when using useDialog or using diallogRef.showModal(). On top of this, testing the modal was difficult because aria-hidden was blocking finding the dialog.
Solution
I added useAriaHidden that handles a working order of operations to set aria-hidden and opening the modal without triggering the warning. I learned that aria-hidden needs to be set BEFORE calling showModal, else there's a race condition and the warning could still show up. Instead, I'm handling it by setting state which updates aria-hidden, then a useEffect that listens to that state change when then calls
showModalorclose. Finally, there's an event listener for close/cancel events that then sets aria-hidden to false.Notes
If we don't want to solve this here, I think documentation explaining that explicit state handling of aria-hidden is required during implementation would be a good alternative. Or... maybe just remove this and only support the open prop, since that works well and fighting this is clearly not fun.
Anyway, the fix:
Screen.Recording.2025-07-30.at.1.46.16.AM-compressed.mp4
Note the lack of aria-hidden console warnings.