Skip to content
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

2352: Announce number of search results to a screen reader #3006

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions native/src/components/CitySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groupBy, transform } from 'lodash'
import React, { ReactElement, ReactNode, useState } from 'react'
import React, { ReactElement, ReactNode, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { View } from 'react-native'
import { AccessibilityInfo, Platform, View } from 'react-native'
import styled from 'styled-components/native'

import { filterSortCities } from 'shared'
@@ -43,6 +43,13 @@ const CitySelector = ({ cities, navigateToDashboard }: CitySelectorProps): React

const resultCities = filterSortCities(cities, filterText, buildConfig().featureFlags.developerFriendly)

useEffect(() => {
// iOS doesn't have live regions to inform a user with a screenreader that there are no more search results
if (resultCities.length === 0 && Platform.OS === 'ios') {
AccessibilityInfo.announceForAccessibility(t('searchResultsCount', { count: 0 }))
}
}, [resultCities, t])

const renderCity = (city: CityModel) => (
<CityEntry key={city.code} city={city} query={filterText} navigateToDashboard={navigateToDashboard} />
)
@@ -76,7 +83,9 @@ const CitySelector = ({ cities, navigateToDashboard }: CitySelectorProps): React
<CityGroup>{t('nearbyCities')}</CityGroup>
<NearbyCities cities={cities} navigateToDashboard={navigateToDashboard} filterText={filterText} />
</CityGroupContainer>
<SearchCounter>{t('search:searchResultsCount', { count: resultCities.length })}</SearchCounter>
<SearchCounter accessibilityLiveRegion={resultCities.length === 0 ? 'assertive' : 'polite'}>
Copy link
Member

Choose a reason for hiding this comment

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

❓ I did not experience any difference between assertive and polite, both was immediately read after the currently typed letter. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I thought I did but I might have been imagining it. According to https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/LiveRegionMode, the main difference is that an assertive live region should also interrupt ongoing speech and a polite one shouldn't. Maybe it's because there was no ongoing speech at the moment? Nothing reading out the key that you had tapped or something?

{t('search:searchResultsCount', { count: resultCities.length })}
</SearchCounter>
{resultCities.length === 0 ? <NothingFound paddingTop /> : cityEntries}
</View>
</View>
15 changes: 12 additions & 3 deletions native/src/routes/SearchModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement, useState } from 'react'
import React, { ReactElement, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { KeyboardAvoidingView, Platform } from 'react-native'
import { AccessibilityInfo, KeyboardAvoidingView, Platform } from 'react-native'
import styled from 'styled-components/native'

import { parseHTML, SEARCH_FINISHED_SIGNAL_NAME, SEARCH_ROUTE, SearchResult, useSearch } from 'shared'
@@ -48,6 +48,13 @@ const SearchModal = ({

const searchResults = useSearch(allPossibleResults, query)

useEffect(() => {
// iOS doesn't have live regions to inform a user with a screenreader that there are no more search results
if (searchResults?.length === 0 && Platform.OS === 'ios') {
AccessibilityInfo.announceForAccessibility(t('searchResultsCount', { count: 0 }))
}
}, [searchResults, t])

if (!searchResults) {
return null
}
@@ -82,7 +89,9 @@ const SearchModal = ({
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={{ flex: 1 }}>
{query.length > 0 && (
<>
<SearchCounter>{t('searchResultsCount', { count: searchResults.length })}</SearchCounter>
<SearchCounter accessibilityLiveRegion={searchResults.length === 0 ? 'assertive' : 'polite'}>
{t('searchResultsCount', { count: searchResults.length })}
</SearchCounter>
<List
items={searchResults}
renderItem={renderItem}
4 changes: 3 additions & 1 deletion web/src/components/CitySelector.tsx
Original file line number Diff line number Diff line change
@@ -61,7 +61,9 @@ const CitySelector = ({ cities, language }: CitySelectorProps): ReactElement =>
placeholderText={t('searchCity')}
spaceSearch={false}
onStickyTopChanged={setStickyTop}>
<SearchCounter>{t('search:searchResultsCount', { count: resultCities.length })}</SearchCounter>
<SearchCounter aria-live={resultCities.length === 0 ? 'assertive' : 'polite'}>
{t('search:searchResultsCount', { count: resultCities.length })}
</SearchCounter>
{resultCities.length === 0 ? <Failure errorMessage='search:nothingFound' /> : groups}
</ScrollingSearchBox>
</Container>
4 changes: 3 additions & 1 deletion web/src/routes/SearchPage.tsx
Original file line number Diff line number Diff line change
@@ -107,7 +107,9 @@ const SearchPage = ({ city, cityCode, languageCode, pathname }: CityRouteProps):
{query.length > 0 && (
<>
<List>
<SearchCounter>{t('searchResultsCount', { count: results.length })}</SearchCounter>
<SearchCounter aria-live={results.length === 0 ? 'assertive' : 'polite'}>
{t('searchResultsCount', { count: results.length })}
</SearchCounter>
{results.map(({ title, content, path, thumbnail }) => (
<SearchListItem
title={title}