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
Show file tree
Hide file tree
Changes from 1 commit
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'
Expand Down Expand Up @@ -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} />
)
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/CitySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 3 additions & 1 deletion web/src/routes/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading