-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Check for :modal selector support before using it
#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,7 @@ if (!("ariaNotify" in Element.prototype) || !("ariaNotify" in Document.prototype | |
| // If there is a modal element on the page, everything outside of it is implicitly inert. | ||
| // This can be checked by seeing if the element is within the modal, if the modal is present. | ||
| (this.element.ownerDocument | ||
| .querySelector(":modal") | ||
| .querySelector(CSS.supports("selector(:modal)") ? ":modal" : "dialog[open]") | ||
|
||
| ?.contains(this.element) ?? | ||
| true) | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback selector
dialog[open]is not semantically equivalent to:modal. The:modalselector matches only dialogs opened withshowModal()(which make outside content inert), whiledialog[open]matches any dialog with theopenattribute, including non-modal dialogs opened withshow()(which don't make outside content inert). This could cause incorrect behavior where non-modal dialogs are incorrectly treated as making content outside them inert. Consider usingdialog[open]:modalas a fallback (which requires the browser to parse it but still functions), or check for the modal state differently (e.g., checking for the presence of a::backdroppseudo-element or using JavaScript to track modal state).See below for a potential fix: