Modal a11y #9696
-
|
Hi, I have 2 questions related to the Modal component.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Now that Top layerOne of the main reasons that you might want to avoid For example, you might use a third-party dependency for certain overlays, like embedded support chat widgets, onboarding tours, toasts, tooltips, etc. Additionally, browser extensions like password managers often add overlays to a page. If all of those also use native dialog/popovers in the top-layer, then everything works as expected. But if any of them are traditional JS overlays not in the top-layer, then those will always display behind the dialog. That can be problematic if users need to access those elements while dialogs are open. Even if all of those did use the top-layer, the browser doesn't give any control over their stacking order. If you show a toast and then open a dialog, the dialog will be on top no matter what. If you want toasts to always be on top, you have to remove them from the DOM and re-add them whenever a new dialog opens, potentially losing state like focus/form input in the process. In the future, perhaps most libraries will be updated to use the top-layer for all overlays and then this problem will reduced, but it's a bit of a chicken and egg issue right now. The same reasoning also applies to AnimationsAnother reason native dialogs might not be a good fit is if need entry or exit animations. Preventing page scrollingMost JS-based modal libraries prevent page scrolling while dialogs are open. Surprisingly, the native Focus behaviorNative Is
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks a lot for the explanation! |
Beta Was this translation helpful? Give feedback.
Now that
<dialog>is widely supported across browsers (not the case when we first built React Aria), it's a common question why you might still use a JS library like React Aria. I'll try to document some of the reasons here.Top layer
One of the main reasons that you might want to avoid
<dialog>is actually also one of its main features: the top-layer. Native dialogs render in a special layer on top of all other content, regardless of the z-index. This is a benefit if your whole app and all of its dependencies are built with this in mind, but that's often not the case.For example, you might use a third-party dependency for certain overlays, like embedded support chat widgets, onboarding …