Repository navigation
Conversation
A MutationObserver does not cross shadow boundaries, and the live region lookup walked up with parentElement only, so an aria-live region that renders its content inside its own shadow root was never announced. - observeDOM observes shadow roots as well, and wraps attachShadow so shadow roots attached later are covered as they are created: a shadow root that is already populated when observation starts never replays those changes. - getElementFromNode maps a ShadowRoot mutation target to its host instead of resolving to undefined - rendering into a shadow root targets the ShadowRoot itself, which has no parentElement. - getTargetAncestor crosses the shadow boundary when walking up, so an aria-live attribute on the host is reachable from inside its shadow root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Announce live regions that render inside a shadow root
Fixes #251.
A live region whose content is rendered inside its own shadow
root (host element with
aria-live, message rendered into the shadow root) isnever announced, while the same region in the light DOM is.
Three coupled causes, each verified against 0.33.0:
observeDOMobserves the container withsubtree: true, and aMutationObserverdoes not cross shadow boundaries, so shadow root changesare never seen.
ShadowRootitself;getElementFromNoderesolves aShadowRoottoundefinedbecause it onlyfalls back to
parentElement.getLiveRegionAttributeswalks up withparentElementonly, so thearia-liveattribute on the host is unreachable from inside its shadow root.What this changes
observeDOM: observesnodeplus every shadow root inside it, and wrapsattachShadowso shadow roots attached later are observed as they are created.Without the wrap, the first content of a newly attached shadow root is missed:
observation starts after that content exists and
MutationObserverdoes notreplay it. Both are undone on teardown.
getElementFromNode: aShadowRoottarget maps to its host.getLiveSpokenPhrase: the ancestor walk crosses the shadow boundary(
assignedSlot ?? parentElement ?? getRootNode().host ?? null).Tests
New:
test/int/ariaLiveShadowRoot.int.test.ts, covering both mutation shapes:aria-livewhose children are replaced through its shadow root(mutation target is the
ShadowRoot);(the walk has to cross the boundary).
Evidence on this branch:
Both new tests fail on
mainwithout the source change (2 failed, the log stopsafter
"button, Trigger shadow live region"), so they are regression testsrather than tests that pass either way.
Context
Found while adding screen reader tests for
@lion/ui(ing-bank/lion), where<lion-input-iban>renders its invalid message in the shadow root oflion-validation-feedbackwitharia-live="assertive". NVDA and VoiceOverannounce that message; the virtual reader did not, so the test could not pin it
down locally. With this fix the
virtualrun speaks"assertive: Error,, Please enter a valid IBAN.".(Separate, cosmetic: the doubled comma comes from joining the additions phrase
and the text phrase of the same live region. Happy to look at that separately if
you want it tidied - it is not needed for this fix.)