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
3 changes: 3 additions & 0 deletions dotcom-rendering/src/components/InteractiveAtom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type InteractiveAtomType = {
elementCss?: string;
isMainMedia?: boolean;
title: string;
customData?: string;
};

export const InteractiveAtom = ({
Expand All @@ -43,6 +44,7 @@ export const InteractiveAtom = ({
elementCss,
isMainMedia,
title,
customData,
}: InteractiveAtomType) => {
const { renderingTarget } = useConfig();

Expand All @@ -51,6 +53,7 @@ export const InteractiveAtom = ({
css={[containerStyles, !!isMainMedia && fullHeightStyles]}
data-atom-id={id}
data-atom-type="interactive"
{...(customData ? { 'data-atom-custom-data': customData } : {})}
>
<Island
priority="feature"
Expand Down
3 changes: 3 additions & 0 deletions dotcom-rendering/src/components/InteractiveLayoutAtom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ export type InteractiveLayoutAtomType = {
elementHtml?: string;
elementJs?: string;
elementCss?: string;
customData?: string;
};

export const InteractiveLayoutAtom = ({
id,
elementHtml,
elementJs,
elementCss,
customData,
}: InteractiveLayoutAtomType) => (
<div
className="interactive interactive-atom"
css={containerStyles}
data-atom-id={id}
data-atom-type="interactive-layout"
{...(customData ? { 'data-atom-custom-data': customData } : {})}
>
{!!elementCss && (
<style
Expand Down
3 changes: 3 additions & 0 deletions dotcom-rendering/src/frontend/schemas/feArticle.json
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,9 @@
"thumbnail"
],
"type": "string"
},
"customData": {
"type": "string"
}
},
"required": [
Expand Down
64 changes: 64 additions & 0 deletions dotcom-rendering/src/lib/interactiveAtoms.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { render } from '@testing-library/react';
import { ConfigProvider } from '../components/ConfigContext';
import { InteractiveAtom } from '../components/InteractiveAtom';
import { InteractiveLayoutAtom } from '../components/InteractiveLayoutAtom';

const mockCustomData = JSON.stringify({ key: 'value' });

describe('Interactive atom custom data attributes', () => {
it('should add custom data attribute to InteractiveAtom on web', () => {
const { container } = render(
<ConfigProvider
value={{
renderingTarget: 'Web',
darkModeAvailable: true,
assetOrigin: '/',
editionId: 'UK',
}}
>
<InteractiveAtom
id="test-id"
title="Test Title"
customData={mockCustomData}
/>
</ConfigProvider>,
);
const el = container.querySelector(
`[data-atom-custom-data='${mockCustomData}']`,
);
expect(el).toBeInTheDocument();
});

it('should add custom data attribute to InteractiveAtom on apps', () => {
const { container } = render(
<ConfigProvider
value={{
renderingTarget: 'Apps',
Comment thread
frederickobrien marked this conversation as resolved.
darkModeAvailable: true,
assetOrigin: '/',
editionId: 'UK',
}}
>
<InteractiveAtom
id="test-id"
title="Test Title"
customData={mockCustomData}
/>
</ConfigProvider>,
);
const el = container.querySelector(
`[data-atom-custom-data='${mockCustomData}']`,
);
expect(el).toBeInTheDocument();
});

it('should add custom data attribute to InteractiveLayoutAtom', () => {
const { container } = render(
<InteractiveLayoutAtom id="test-id" customData={mockCustomData} />,
);
const el = container.querySelector(
`[data-atom-custom-data='${mockCustomData}']`,
);
expect(el).toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions dotcom-rendering/src/lib/renderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export const renderElement = ({
elementHtml={element.html}
elementJs={element.js}
elementCss={element.css}
customData={element.customData}
/>
);
}
Expand All @@ -447,6 +448,7 @@ export const renderElement = ({
elementJs={element.js}
elementCss={element.css}
title={element.title}
customData={element.customData}
/>
);
case 'model.dotcomrendering.pageElements.InteractiveBlockElement': {
Expand Down
3 changes: 3 additions & 0 deletions dotcom-rendering/src/model/block-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,9 @@
"thumbnail"
],
"type": "string"
},
"customData": {
"type": "string"
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export interface InteractiveAtomBlockElement {
css?: string;
placeholderUrl?: string;
role?: RoleType | 'fullWidth';
customData?: string;
}

// Can't guarantee anything in interactiveBlockElement :shrug:
Expand Down
Loading