-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 1 commit
30b3684
749cc69
c853060
dbfe361
1aa01a4
3c11d35
ec867d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -13,10 +15,11 @@ import styles from './eventCard.module.scss'; | |
|
||
interface Props { | ||
event: EventFieldsFragment; | ||
link: string; | ||
onClick?: (id: string) => void; | ||
} | ||
|
||
const EventCard: React.FC<Props> = ({ event, onClick }) => { | ||
const EventCard: React.FC<Props> = ({ event, link, onClick }) => { | ||
const { t } = useTranslation(); | ||
const locale = useLocale(); | ||
|
||
|
@@ -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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 You can fix this by adding as prop to Link
More info can be found here i18next/next-i18next#413 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could remove unused property