Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: changed the way screenreaders read the content of tooltips in c…
Browse files Browse the repository at this point in the history
…horopleths (#4179)
  • Loading branch information
hasan-ozaynaci authored Apr 13, 2022
1 parent ecbe053 commit 20d70ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert } from '@corona-dashboard/common';
import { isDefined } from 'ts-is-present';
import { Markdown } from '~/components/markdown';
import { Markdown, VisuallyHidden } from '~/components';
import { Box } from '~/components/base';
import { useIntl } from '~/intl';
import { replaceVariablesInText } from '~/utils/replace-variables-in-text';
import { ChoroplethDataItem } from '../logic';
Expand Down Expand Up @@ -71,6 +72,9 @@ export function ChoroplethTooltip<T extends ChoroplethDataItem>(
formatDateSpan,
});

// This line is to make sure the content is readible by screenreaders and does not skip numbers after a new line
const ariaContent = content.replace(/(\n|\*)/g, '');

return (
<TooltipContent
title={data.featureName}
Expand All @@ -87,7 +91,10 @@ export function ChoroplethTooltip<T extends ChoroplethDataItem>(
data.dataItem[data.dataConfig.metricProperty] as unknown as number
}
>
<Markdown content={content} />
<VisuallyHidden>{ariaContent}</VisuallyHidden>
<Box aria-hidden>
<Markdown content={content} />
</Box>
</TooltipSubject>
</TooltipContent>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ export function TooltipContent(props: IProps) {
aria-live="polite"
>
<TooltipHeader href={link}>
<Text
variant="choroplethTooltipHeader"
/**
* If there's no link do not read the tooltip title because a
* screenreader will also read the choropleth link which contains the
* name of a region.
*/
aria-hidden={link ? 'true' : 'false'}
>
<Text variant="choroplethTooltipHeader">
<StyledLocationIcon>
<Locatie />
</StyledLocationIcon>
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export { ChoroplethLegenda } from './choropleth-legenda';
export { SEOHead } from './seo-head';
export { PageKpi } from './page-kpi';
export { PageBarScale } from './page-barscale';
export { VisuallyHidden } from './visually-hidden';

0 comments on commit 20d70ec

Please sign in to comment.