Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { defaultRenderLinkFunction } from '~shared/helpers/routing/link';

import './BlockImageGrid.scss';
import { CopyrightAttribution } from '~shared/components/CopyrightAttribution';
import { generateSmartLink } from '~shared/components/SmartLink/SmartLink.tsx';
import { tText } from '~shared/helpers/translation-functions.ts';

export const BlockImageGrid: FunctionComponent<BlockImageGridProps> = ({
elements = [],
Expand Down Expand Up @@ -111,22 +113,41 @@ export const BlockImageGrid: FunctionComponent<BlockImageGridProps> = ({
<div
className={clsx('c-block-grid', `text-align-${textAlign}`, `item-align-${align}`, className)}
>
{elements.map((element, index) => (
<div
key={`block-grid-${element?.action?.value || element.title || null}${index}`}
className={clsx('c-block-grid__item')}
style={{
width: itemWidth,
margin: `${Math.round(verticalMargin / 2)}px ${Math.round(horizontalMargin / 2)}px`,
}}
>
{renderLink(
element.action,
renderGridImage(element),
element.title || element.buttonTitle || element.titleAbove
)}
</div>
))}
{elements.map((element, index) => {
const title = element.title || element.buttonTitle || element.titleAbove || '';
let elementAriaLabel: string;

if (element.imageLabel?.text) {
elementAriaLabel = tText('aria-label block image grid item met label', {
label: element.imageLabel.text,
title,
});
} else {
elementAriaLabel = tText('aria-label block image grid item', {
title,
});
}

return (
<div
key={`block-grid-${element?.action?.value || element.title || null}${index}`}
className={clsx('c-block-grid__item')}
style={{
width: itemWidth,
margin: `${Math.round(verticalMargin / 2)}px ${Math.round(horizontalMargin / 2)}px`,
}}
>
{generateSmartLink(
element.action,
renderGridImage(element),
title,
undefined,
undefined,
elementAriaLabel
)}
</div>
);
})}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const SmartLink: FunctionComponent<SmartLinkProps> = ({
target={LinkTarget.Blank}
rel="noopener noreferrer"
title={title}
aria-label={ariaLabel}
className={clsx(className, { 'a-link__no-styles': removeStyles })}
onClick={() => AdminConfigManager.getConfig().handlers.onExternalLink(fullUrl)}
onKeyUp={onKeyUpHandler}
Expand All @@ -150,6 +151,7 @@ export const SmartLink: FunctionComponent<SmartLinkProps> = ({
target={LinkTarget.Blank}
rel="noopener noreferrer"
title={title}
aria-label={ariaLabel}
className={clsx(className, { 'a-link__no-styles': removeStyles })}
onClick={() => AdminConfigManager.getConfig().handlers.onExternalLink(fullUrl)}
onKeyUp={onKeyUpHandler}
Expand Down Expand Up @@ -284,7 +286,8 @@ export const generateSmartLink = (
children: ReactNode,
title?: string,
className?: string,
tabIndex?: number
tabIndex?: number,
ariaLabel?: string
// biome-ignore lint/suspicious/noExplicitAny: todo
): ReactElement<any, any> | null => {
return (
Expand All @@ -294,6 +297,7 @@ export const generateSmartLink = (
className={className}
key={`smart-link-${action?.value}-${title}-${className}`}
tabIndex={tabIndex}
ariaLabel={ariaLabel}
>
{children}
</SmartLink>
Expand Down