@@ -15,6 +15,7 @@ import { useOnce } from '../lib/useOnce';
15
15
import { palette as themePalette } from '../palette' ;
16
16
import type { RoleType } from '../types/content' ;
17
17
import { Caption } from './Caption' ;
18
+ import { useConfig } from './ConfigContext' ;
18
19
import { defaultRoleStyles } from './Figure' ;
19
20
import { Placeholder } from './Placeholder' ;
20
21
@@ -324,6 +325,7 @@ export const InteractiveBlockComponent = ({
324
325
const wrapperRef = useRef < HTMLDivElement > ( null ) ;
325
326
const placeholderLinkRef = useRef < HTMLAnchorElement > ( null ) ;
326
327
const [ loaded , setLoaded ] = useState ( false ) ;
328
+ const { darkModeAvailable } = useConfig ( ) ;
327
329
useOnce ( ( ) => {
328
330
// We've brought the behavior from boot.js into this file to avoid loading 2 extra scripts
329
331
if (
@@ -345,16 +347,22 @@ export const InteractiveBlockComponent = ({
345
347
346
348
// Datawrapper-specific fix to suppress scrollbars appearing
347
349
if ( url . includes ( 'datawrapper' ) ) {
348
- iframe . scrolling = 'no' ;
349
350
iframe . scrolling = 'no' ;
350
351
// Turn off dark mode for Datawrapper embeds on web
351
352
// This should be removed if/when dark mode is implements on the website
352
353
if (
353
- ! document . querySelector ( '.ios' ) ||
354
+ ! document . querySelector ( '.ios' ) &&
354
355
! document . querySelector ( '.android' )
355
356
) {
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
+ }
358
366
}
359
367
}
360
368
0 commit comments