docs: add aria-live enhancement for search results accessibility (#issue)#21019
Merged
docs: add aria-live enhancement for search results accessibility (#issue)#21019
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pelikhan
March 15, 2026 03:29
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a client-side accessibility enhancement for Starlight/Pagefind search by ensuring a live region is applied to dynamically inserted search results so screen readers announce updates.
Changes:
- Introduces a new client script that detects the search results container and applies
aria-live/aria-atomic. - Wires the new script into the docs site head so it runs on initial load and Astro client-side navigation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/src/scripts/search-aria.ts | Adds a MutationObserver-based enhancement to apply ARIA live-region attributes to dynamically inserted search UI elements. |
| docs/src/components/CustomHead.astro | Loads the new search ARIA enhancement script on all docs pages. |
Comments suppressed due to low confidence (1)
docs/src/scripts/search-aria.ts:65
- The MutationObserver is attached to
document.bodywith{ subtree: true }and will stay active until a matching results element appears. If a user never opens search, this observer remains for the full session and will process unrelated DOM mutations. Consider narrowing the observation scope (e.g., observe the search dialog once it exists) and/or adding a timeout/interaction-triggered setup so the observer doesn’t live indefinitely.
activeObserver = null;
}
});
activeObserver.observe(document.body, { childList: true, subtree: true });
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+34
to
+36
| if (el && !el.getAttribute('aria-live')) { | ||
| el.setAttribute('aria-live', 'polite'); | ||
| el.setAttribute('aria-atomic', 'false'); |
This was referenced Mar 15, 2026
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.
Summary
Addresses the 🟡 accessibility warning from the Multi-Device Docs Testing Report (2026-03-15) regarding missing
aria-liveregions on the search results container.Background
Starlight/pagefind renders the search results container dynamically via JavaScript — it doesn't exist in the initial HTML. Static analysis tools therefore report it as "not detected". Adding
aria-live="polite"to this container ensures screen readers announce result counts as users type in the search box.Changes
docs/src/scripts/search-aria.ts(new)A small client-side TypeScript script (modelled after the existing
responsive-tables.ts) that:MutationObserverto watch for the pagefind search results container being added to the DOMaria-live="polite"andaria-atomic="false"on it once foundastro:page-loadso only one observer is active at a time (no leaks across client-side navigation).pagefind-ui__results,dialog[aria-label] ul[role="listbox"],dialog[aria-label] [role="status"])docs/src/components/CustomHead.astroImports the new script alongside the existing
responsive-tables.tsimport.Security Summary
No security vulnerabilities were introduced or discovered. CodeQL scan returned 0 alerts.