Skip to content

Commit 921cc20

Browse files
Merge pull request #13637 from guardian/disable-datawrapper-dark-mode-on-web
Disable dark mode for Datawrapper embeds on web
2 parents c830a93 + 775dc67 commit 921cc20

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

dotcom-rendering/src/components/InteractiveBlockComponent.importable.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useOnce } from '../lib/useOnce';
1515
import { palette as themePalette } from '../palette';
1616
import type { RoleType } from '../types/content';
1717
import { Caption } from './Caption';
18+
import { useConfig } from './ConfigContext';
1819
import { defaultRoleStyles } from './Figure';
1920
import { Placeholder } from './Placeholder';
2021

@@ -324,6 +325,7 @@ export const InteractiveBlockComponent = ({
324325
const wrapperRef = useRef<HTMLDivElement>(null);
325326
const placeholderLinkRef = useRef<HTMLAnchorElement>(null);
326327
const [loaded, setLoaded] = useState(false);
328+
const { darkModeAvailable } = useConfig();
327329
useOnce(() => {
328330
// We've brought the behavior from boot.js into this file to avoid loading 2 extra scripts
329331
if (
@@ -346,6 +348,22 @@ export const InteractiveBlockComponent = ({
346348
// Datawrapper-specific fix to suppress scrollbars appearing
347349
if (url.includes('datawrapper')) {
348350
iframe.scrolling = 'no';
351+
// Turn off dark mode for Datawrapper embeds on web
352+
// This should be removed if/when dark mode is implements on the website
353+
if (
354+
!document.querySelector('.ios') &&
355+
!document.querySelector('.android')
356+
) {
357+
const prefersDarkScheme = window.matchMedia(
358+
'(prefers-color-scheme: dark)',
359+
).matches;
360+
const darkMode = darkModeAvailable && prefersDarkScheme;
361+
if (!darkMode) {
362+
iframe.src +=
363+
(iframe.src.includes('?') ? '&' : '?') +
364+
'dark=false';
365+
}
366+
}
349367
}
350368

351369
setupWindowListeners(iframe);

0 commit comments

Comments
 (0)