Skip to content

Commit 85c04c2

Browse files
authored
[Accessibility Audit] Announce via screen reader when no results for search docs (#55551)
1 parent 2b1c3b8 commit 85c04c2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ search:
4242
clear_search_query: Clear
4343
view_all_search_results: View more results
4444
no_results_found: No results found
45+
no_results_found_announcement: 'Search Docs: No results found'
4546
search_docs_with_query: Search docs for "{{query}}"
4647
privacy_disclaimer: For product and service improvement purposes, the GitHub Docs team will retain questions and answers generated in the Docs search function. Please see the <a href="https://docs.github.com/privacy"><u>GitHub Privacy Statement</u></a> to review how GitHub collects and uses your data.
4748
ai:

src/fixtures/fixtures/data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ search:
4242
clear_search_query: Clear
4343
view_all_search_results: View more results
4444
no_results_found: No results found
45+
no_results_found_announcement: 'Search Docs: No results found'
4546
search_docs_with_query: Search docs for "{{query}}"
4647
privacy_disclaimer: For product and service improvement purposes, the GitHub Docs team will retain questions and answers generated in the Docs search function. Please see the <a href="https://docs.github.com/privacy"><u>GitHub Privacy Statement</u></a> to review how GitHub collects and uses your data.
4748
ai:

src/search/components/input/SearchOverlay.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function SearchOverlay({
9191
const [aiCouldNotAnswer, setAICouldNotAnswer] = useState<boolean>(false)
9292
const [showSpinner, setShowSpinner] = useState(false)
9393
const [scrollPos, setScrollPos] = useState(0)
94+
const [announcement, setAnnouncement] = useState<string>('')
9495

9596
const { hasOpenHeaderNotifications } = useSharedUIContext()
9697

@@ -188,6 +189,7 @@ export function SearchOverlay({
188189

189190
// Combine options for key navigation
190191
const [combinedOptions, generalOptionsWithViewStatus, aiOptionsWithUserInput] = useMemo(() => {
192+
setAnnouncement('')
191193
let generalOptionsWithViewStatus = [...generalSearchResults]
192194
const aiOptionsWithUserInput = [...userInputOptions, ...filteredAIOptions]
193195
const combinedOptions = [] as Array<{
@@ -209,6 +211,7 @@ export function SearchOverlay({
209211
} as unknown as GeneralSearchHit)
210212
}
211213
} else if (urlSearchInputQuery.trim() !== '' && !searchLoading) {
214+
setAnnouncement(t('search.overlay.no_results_found_announcement'))
212215
generalOptionsWithViewStatus.push({
213216
title: t('search.overlay.no_results_found'),
214217
isNoResultsFound: true,
@@ -815,6 +818,22 @@ export function SearchOverlay({
815818
dangerouslySetInnerHTML={{ __html: t('search.overlay.privacy_disclaimer') }}
816819
/>
817820
</footer>
821+
<div
822+
aria-live="assertive"
823+
style={{
824+
position: 'absolute',
825+
width: '1px',
826+
height: '1px',
827+
padding: '0',
828+
margin: '-1px',
829+
overflow: 'hidden',
830+
clip: 'rect(0, 0, 0, 0)',
831+
whiteSpace: 'nowrap',
832+
border: '0',
833+
}}
834+
>
835+
{announcement}
836+
</div>
818837
</Overlay>
819838
</>
820839
)

0 commit comments

Comments
 (0)