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

PT-510 | Accessibility improvements #53

Merged
merged 7 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions public/static/locales/en/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"pageTitle": "Event",
"photographerText": "Photo: {{photographer}}",
"eventImageAltText": "Event image",
"contactPerson": "Contact person",
"occurrencesTitle": "Occurrences ({{count}} pcs)",
"shareLinks": {
Expand Down
1 change: 1 addition & 0 deletions public/static/locales/fi/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"pageTitle": "Tapahtuma",
"photographerText": "Kuva: {{photographer}}",
"eventImageAltText": "Tapahtuman kuva",
"contactPerson": "Yhteyshenkilö",
"occurrencesTitle": "Tapahtumat ({{count}} kpl)",
"shareLinks": {
Expand Down
1 change: 1 addition & 0 deletions public/static/locales/sv/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"pageTitle": "Evenemang",
"photographerText": "Foto: {{photographer}}",
"eventImageAltText": "Händelsebild",
"contactPerson": "Kontakt person",
"occurrencesTitle": "Händelsetider ({{count}} st)",
"shareLinks": {
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/form/errorMessage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

color: var(--color-error);
line-height: var(--label-height);
font-size: var(--fontsize-body-m);
font-size: var(--fontsize-body-l);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
line-height: 1.5rem;
white-space: nowrap;
overflow: hidden;
font-size: var(--fontsize-body-m);
font-size: var(--fontsize-body-l);
text-overflow: ellipsis;

input {
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/table/table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
--color-cell: var(--color-black-90);
--color-cell-header: var(--color-black-90);

--fontsize-cell: var(--fontsize-body-m);
--fontsize-cell-header: var(--fontsize-body-m);
--fontsize-cell: var(--fontsize-body-l);
--fontsize-cell-header: var(--fontsize-body-l);

--margin-bottom-table: var(--spacing-m);
--spacing-cell: var(--spacing-s);
--spacing-cell: var(--spacing-m);

--expanded-row-border-color: var(--color-black-30);
}
Expand Down
2 changes: 1 addition & 1 deletion src/domain/event/EventPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const EventPage = (): ReactElement => {
)}
<EventImage
imageUrl={imageUrl}
imageAltText={imageAltText}
imageAltText={imageAltText || t('event:eventImageAltText')}
photographerName={photographerName}
/>
<EventBasicInfo event={eventData.event} />
Expand Down
2 changes: 1 addition & 1 deletion src/domain/event/dateFilter/dateFilter.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.dateFilter {
--date-filter-width: 160px;
--inactive-date-filter-color: lightgrey;
--inactive-date-filter-color: var(--color-black-60);
}

.dateFilter {
Expand Down
82 changes: 36 additions & 46 deletions src/domain/event/eventCard/EventCard.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import { IconLocation } from 'hds-react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import { EventFieldsFragment } from '../../../generated/graphql';
import useLocale from '../../../hooks/useLocale';
import { Link } from '../../../i18n';
import IconClock from '../../../icons/IconClock';
import getLocalisedString from '../../../utils/getLocalisedString';
import PlaceText from '../../place/placeText/PlaceText';
Expand All @@ -13,10 +15,11 @@ import styles from './eventCard.module.scss';

interface Props {
event: EventFieldsFragment;
link: string;
onClick?: (id: string) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could remove unused property

}

const EventCard: React.FC<Props> = ({ event, onClick }) => {
const EventCard: React.FC<Props> = ({ event, link, onClick }) => {
const { t } = useTranslation();
const locale = useLocale();

Expand All @@ -26,55 +29,42 @@ const EventCard: React.FC<Props> = ({ event, onClick }) => {
const image = event.images[0]?.url;
const time = getEventStartTimeStr(event, locale, t);

const handleClick = () => {
if (onClick) {
onClick(event.id || '');
}
};

const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Enter') {
handleClick();
}
};

return (
<div
role="button"
className={styles.eventCard}
tabIndex={0}
onClick={handleClick}
onKeyDown={handleKeyDown}
aria-label={t('event:eventCard.ariaLabelOpenEvent', {
eventName: name,
})}
>
<div
className={styles.imageWrapper}
style={{
backgroundImage: `url(${
image || getEventPlaceholderImage(id || '')
})`,
}}
></div>
<div className={styles.contentWrapper}>
<div className={styles.titleWrapper}>
<div className={styles.title}>{name}</div>
<div className={styles.description}>{description}</div>
</div>
<div className={styles.occurrenceInfoWrapper}>
<div className={styles.textWithIcon}>
<IconClock />
{time}
<Link href={link}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the dynamic routing is not working properly here. When I'm clicking event card i get this error message
Näyttökuva 2020-10-9 kello 14 34 50
And on event page
Näyttökuva 2020-10-9 kello 14 30 34

You can fix this by adding as prop to Link
e.g.

<Link
      href={`${ROUTES.EVENT_DETAILS.replace(':id', '[eventId]')}?eventId=${
        event.id
      }`}
      as={ROUTES.EVENT_DETAILS.replace(':id', event.id)}
    >

More info can be found here i18next/next-i18next#413

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm next docs mention that this props is used before version Next.js 9.5.3. Need to check if updating next would help 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I think I have seen that error evenr before when running locally

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem existed already before this PR. next-i18next still seems to use 'as' prop internally. Here's source code for that component https://github.com/isaachinman/next-i18next/blob/master/src/components/Link.tsx

But hopefully just updating next.js to latest version does the magic

<a
className={styles.eventCard}
// TODO: should we use this? maybe not, the screen reader might not read everything
// aria-label={t('event:eventCard.ariaLabelOpenEvent', {
// eventName: name,
// })}
>
<div
className={styles.imageWrapper}
style={{
backgroundImage: `url(${
image || getEventPlaceholderImage(id || '')
})`,
}}
></div>
<div className={styles.contentWrapper}>
<div className={styles.titleWrapper}>
<div className={styles.title}>{name}</div>
<div className={styles.description}>{description}</div>
</div>
<div className={styles.textWithIcon}>
<IconLocation />
<PlaceText placeId={event.location?.id || ''} />
<div className={styles.occurrenceInfoWrapper}>
<div className={styles.textWithIcon}>
<IconClock />
{time}
</div>
<div className={styles.textWithIcon}>
<IconLocation />
<PlaceText placeId={event.location?.id || ''} />
</div>
</div>
<EventKeywords event={event} />
</div>
<EventKeywords event={event} />
</div>
</div>
</a>
</Link>
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/domain/event/eventCard/eventCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
display: grid;
cursor: pointer;
background-color: var(--background-color-event-card);
text-decoration: none;
color: black;

@include respond_above(sm) {
grid-template-columns: var(--width-image) 1fr;
Expand Down
2 changes: 2 additions & 0 deletions src/domain/event/occurrences/Occurrences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ const Occurrences: React.FC<Props> = ({
return (
<button
aria-label={t('occurrence:showOccurrenceDetails')}
// row.isExpanded is undefined when is not expanded for some reason
aria-expanded={row.isExpanded ? true : false}
{...row.getToggleRowExpandedProps()}
>
<IconAngleDown
Expand Down
6 changes: 1 addition & 5 deletions src/domain/events/eventList/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ const EventList = ({
setSort(option.value);
};

const goToEventDetailsPage = (id: string) => {
Router.push(ROUTES.EVENT_DETAILS.replace(':id', id));
};

return (
<div className={styles.eventList}>
<div className={styles.headingRow}>
Expand Down Expand Up @@ -75,7 +71,7 @@ const EventList = ({
<EventCard
key={index}
event={event}
onClick={goToEventDetailsPage}
link={ROUTES.EVENT_DETAILS.replace(':id', event.id)}
/>
);
})}
Expand Down