Skip to content

Commit 775dc67

Browse files
Make logic betterer
1 parent 9c8548b commit 775dc67

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 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 (
@@ -345,16 +347,22 @@ export const InteractiveBlockComponent = ({
345347

346348
// Datawrapper-specific fix to suppress scrollbars appearing
347349
if (url.includes('datawrapper')) {
348-
iframe.scrolling = 'no';
349350
iframe.scrolling = 'no';
350351
// Turn off dark mode for Datawrapper embeds on web
351352
// This should be removed if/when dark mode is implements on the website
352353
if (
353-
!document.querySelector('.ios') ||
354+
!document.querySelector('.ios') &&
354355
!document.querySelector('.android')
355356
) {
356-
iframe.src +=
357-
(iframe.src.includes('?') ? '&' : '?') + 'dark=false';
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+
}
358366
}
359367
}
360368

0 commit comments

Comments
 (0)