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

UHF-8804: Fix card accessibility issues #1046

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/js/district-and-project-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/health-station-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/linkedevents.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/maternity-and-child-health-clinic-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/news-archive.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/school-search.min.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/js/react/apps/linkedevents/components/SeeAllButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function SeeAllButton() {
data-hds-variant="secondary"
href={eventsUrl}
title={Drupal.t('Refine search in tapahtumat.hel.fi', {}, { context: 'Events search' })} />
<ExternalLink href={eventsUrl} title={<span>{Drupal.t('Open large version of the map', {}, {context: 'React search: result display'})}</span>} />
</div>
);
}
Expand Down
20 changes: 8 additions & 12 deletions src/js/react/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type MetadataType from '@/types/MetadataType';
import type TagType from '@/types/TagType';
import Tags from './Tags';
import Icon from './Icon';
import ExternalLink from '@/react/common/ExternalLink';

const Metarow = ({ icon, label, content, langAttribute } : MetadataType) => (
<div className="card__meta">
Expand Down Expand Up @@ -87,20 +88,15 @@ function CardItem({

<div className="card__text">
<HeadingTag className="card__title">
<a href={cardUrl} className="card__link" {...cardUrlExternal && { 'data-is-external': 'true' }} rel="bookmark">
<span>{ cardTitle }</span>
{cardUrlExternal &&
<span className="link__type link__type--external" aria-label={`(${Drupal.t(
'Link leads to external service',
{},
{ context: 'Explanation for screen-reader software that the icon visible next to this link means that the link leads to an external service.' },
)})`} />
}
</a>
{!cardUrlExternal ? (
<a href={cardUrl} className="card__link" rel="bookmark">{ cardTitle }</a>
) : (
<ExternalLink href={cardUrl} title={cardTitle} className="card__link" rel="bookmark" />
)}
</HeadingTag>
{cardCategoryTag &&
<div className="card__category">
<Tags tags={[cardCategoryTag]} />
<Tags tags={[cardCategoryTag]} insideCard />
</div>
}

Expand Down Expand Up @@ -156,7 +152,7 @@ function CardItem({

{cardTags && cardTags.length > 0 &&
<div className="card__tags">
<Tags tags={cardTags} langAttribute={langAttribute} />
<Tags tags={cardTags} langAttribute={langAttribute} insideCard />
</div>
}
</div>
Expand Down
15 changes: 14 additions & 1 deletion src/js/react/common/ExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ type ExternalLinkProps = {
title: string | JSX.Element;
'data-hds-component'?: string;
'data-hds-variant'?: string;
rel?: string;
};

const ExternalLink = ({ href, title, 'data-hds-component': dataHdsComponent, 'data-hds-variant': dataHdsVariant }: ExternalLinkProps) => {
const ExternalLink = (
{
href,
title,
className,
'data-hds-component': dataHdsComponent,
'data-hds-variant': dataHdsVariant,
rel,
}: ExternalLinkProps
) =>
{
const dataAttributes = {
...(dataHdsComponent && { 'data-hds-component': dataHdsComponent }),
...(dataHdsVariant && { 'data-hds-variant': dataHdsVariant }),
Expand All @@ -15,8 +26,10 @@ const ExternalLink = ({ href, title, 'data-hds-component': dataHdsComponent, 'da
return (
<a
href={href}
className={className}
data-is-external='true'
{...dataAttributes}
rel={rel}
>
{title}

Expand Down
37 changes: 21 additions & 16 deletions src/js/react/common/Tags.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import React from 'react';
import type TagType from '@/types/TagType';

interface TagsProps {
tags: Array<TagType>;
isInteractive?: boolean;
langAttribute?: any;
insideCard?: boolean;
}

export function Tags({ tags, isInteractive, langAttribute }: TagsProps): JSX.Element {
export function Tags({ tags, isInteractive, langAttribute, insideCard }: TagsProps): JSX.Element {
const typeClass = isInteractive ? 'content-tags__tags--interactive' : 'content-tags__tags--static';

return (
<section
className="content-tags content-tags--card"
aria-label={
Drupal.t('Tags', {}, { context: 'Label for screen reader software users explaining that this is a list of tags related to this page.' })
}>
<ul className={`content-tags__tags ${typeClass}`}>
{tags.map((item: TagType, key: number) => (
<li key={`{item.tag}-${key}`} className={`content-tags__tags__tag ${item.color ? `content-tags__tags__tag--${item.color}` : ''}`} {...langAttribute}>
<span>{item.tag}</span>
</li>
),
)}
</ul>
</section>
// When inside a card, use a div instead of a section to avoid duplicating the aria-label description on each card.
const Element = insideCard ? 'div' : 'section';

return React.createElement(
Element,
{
className: 'content-tags content-tags--card',
'aria-label': Drupal.t('Tags', {}, { context: 'Label for screen reader software users explaining that this is a list of tags related to this page.' }),
role: insideCard ? 'group' : undefined, // When inside a card, use role="group" to group the tags together.
},
<ul className={`content-tags__tags ${typeClass}`}>
{tags.map((item: TagType, key: number) => (
<li key={`{item.tag}-${key}`} className={`content-tags__tags__tag ${item.color ? `content-tags__tags__tag--${item.color}` : ''}`} {...langAttribute}>
<span>{item.tag}</span>
</li>
),
)}
</ul>
);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/component/card.twig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

{% if card_tags %}
<div class="card__tags">
{% embed '@hdbt/misc/tag-list.twig' with { tags: card_tags, addSpan: true, tag_container_class: ' content-tags--card' } %}
{% embed '@hdbt/misc/tag-list.twig' with { tags: card_tags, addSpan: true, tag_container_class: ' content-tags--card', inside_card: true } %}
{% endembed %}
</div>
{% endif %}
Expand Down
11 changes: 9 additions & 2 deletions templates/misc/tag-list.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{% set element = 'section' %}
{% set role = '' %}
{% if inside_card %}
{% set element = 'div' %}
{% set role = 'role="group"' %}
{% endif %}

{% if type == 'interactive' %}
{% set type_class = 'content-tags__tags--interactive' %}
{% else %}
Expand All @@ -6,7 +13,7 @@

{% set content_tags_id = 'hdbt-content_tags_id-' ~ random() %}

<section class="content-tags {{ tag_container_class }}" aria-labelledby="{{ content_tags_id }}">
<{{element}} {{role}} class="content-tags {{ tag_container_class }}" aria-labelledby="{{ content_tags_id }}">
<span id="{{ content_tags_id }}" class="is-hidden" {{ alternative_language ? create_attribute(({ 'lang': lang_attributes.fallback_lang, 'dir': lang_attributes.fallback_dir })) }}>
{{ 'Tags'|t({}, {'context': 'Label for screen reader software users explaining that this is a list of tags related to this page.'}) }}
</span>
Expand All @@ -20,4 +27,4 @@
{% endfor %}
{% endblock %}
</ul>
</section>
</{{element}}>