Skip to content

Ensure live region is appended to role="dialog" #12

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

Merged
merged 1 commit into from
Apr 11, 2025

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented Apr 10, 2025

Fixes: #13

Ensures that live region gets appended to role="dialog" in addition to <dialog>.

It'd be nice to add tests for dialog scenarios we use ariaNotify in covering <dialog> and [role="dialog"]. It doesn't look like there are any right now - it looks a bit involved, so I will not tackle that in this PR. Filed: #14

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@khiga8 khiga8 requested a review from Copilot April 10, 2025 21:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the logic for appending the live region so that, in addition to native dialog elements, elements with role="dialog" are also considered.

  • Added an extra check for elements with the attribute role="dialog"
  • Ensured proper fallback to getRootNode() when no dialog is found
Comments suppressed due to low confidence (1)

ariaNotify-polyfill.js:76

  • Consider adding unit tests to verify that the live region is correctly appended when an ancestor element with role='dialog' is present, ensuring this new logic behaves as expected across different DOM structures.
this.element.closest("dialog") || this.element.closest("[role='dialog']") || this.element.getRootNode()

@khiga8 khiga8 marked this pull request as ready for review April 10, 2025 22:52
@khiga8 khiga8 requested a review from a team as a code owner April 10, 2025 22:52
Copy link
Contributor

@smockle smockle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: Is it necessary to create the <live-region> element inside a non-modal dialog, or only necessary for modal dialogs?

Either way, it’s not harmful to create it inside—and the existing check did not distinguish between modal and non-modal <dialog> elements—so I’m okay approving this PR.

@smockle smockle merged commit 8545080 into main Apr 11, 2025
3 checks passed
@smockle smockle deleted the kh-ensure-dialog-works branch April 11, 2025 12:50
@smockle
Copy link
Contributor

smockle commented Apr 11, 2025

Thanks for contributing! This is being released in v2.1.0: https://github.com/github/ariaNotify-polyfill/releases/tag/v2.1.0.

@khiga8
Copy link
Contributor Author

khiga8 commented Apr 11, 2025

@smockle that is an excellent question! 👀

Looking through dialog testing results from @TylerJDev, it does seem like the problem is with modal dialogs!

Note: In the test results doc linked above:

  • There are failure results for "HTML Dialog with role="alert" and aria-modal="false" live region test.
    • Initially, this made me think that non-modal dialogs also have problems with outside live regions. However, this test case is still using showModal() so its wired up like a modal dialog despite the aria-modal="false" override.
  • All results are successful for "HTML Dialog with role="alert" using .show() to activate live region test"

Since the "modal-ness" of <dialog> is controlled by whether the showModal() or show() helper is used, I think it's safer to add a live region for all <dialog>. But maybe for non-native dialogs, this could be scoped down to:

 this.element.closest("dialog") || this.element.closest("[aria-modal='dialog']") 

I don't think what we have hurts though, and it's probably worth testing again before we scope down!

@smockle
Copy link
Contributor

smockle commented Apr 11, 2025

Semi-related: It’s possible to detect whether a <dialog> is modal (without monkey-patching showModal()/show()) — I did this for the headingoffset-polyfill: https://github.com/smockle/headingoffset-polyfill/blob/c236e74dd3ce4db46d78815029356f24edc9f18d/headingoffset-polyfill.js#L142-L147

@khiga8
Copy link
Contributor Author

khiga8 commented Apr 11, 2025

NICE!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] ariaNotify does not add live region to [role="dialog"]
2 participants