@@ -4,7 +4,7 @@ import 'echarts/lib/component/toolbox';
4
4
import 'echarts/lib/component/brush' ;
5
5
import 'zrender/lib/svg/svg' ;
6
6
7
- import { useMemo } from 'react' ;
7
+ import { useId , useMemo } from 'react' ;
8
8
import type { Theme } from '@emotion/react' ;
9
9
import { css , Global , useTheme } from '@emotion/react' ;
10
10
import styled from '@emotion/styled' ;
@@ -181,6 +181,7 @@ export interface BaseChartProps {
181
181
* Chart height
182
182
*/
183
183
height ?: ReactEChartOpts [ 'height' ] ;
184
+
184
185
/**
185
186
* If data is grouped by date; then apply default date formatting to x-axis
186
187
* and tooltips.
@@ -478,6 +479,7 @@ function BaseChart({
478
479
: false ;
479
480
480
481
const isTooltipPortalled = tooltip ?. appendToBody ;
482
+ const chartId = useId ( ) ;
481
483
482
484
const chartOption = useMemo ( ( ) => {
483
485
const seriesData =
@@ -496,6 +498,7 @@ function BaseChart({
496
498
addSecondsToTimeFormat,
497
499
utc,
498
500
bucketSize,
501
+ chartId : isTooltipPortalled ? chartId : undefined ,
499
502
...tooltip ,
500
503
className : isTooltipPortalled
501
504
? `${ tooltip ?. className ?? '' } chart-tooltip-portal`
@@ -568,6 +571,7 @@ function BaseChart({
568
571
brush,
569
572
} ;
570
573
} , [
574
+ chartId ,
571
575
color ,
572
576
resolvedSeries ,
573
577
isTooltipPortalled ,
@@ -662,7 +666,11 @@ function BaseChart({
662
666
} , [ style , autoHeightResize , height , width ] ) ;
663
667
664
668
return (
665
- < ChartContainer autoHeightResize = { autoHeightResize } data-test-id = { dataTestId } >
669
+ < ChartContainer
670
+ id = { isTooltipPortalled ? chartId : undefined }
671
+ autoHeightResize = { autoHeightResize }
672
+ data-test-id = { dataTestId }
673
+ >
666
674
{ isTooltipPortalled && < Global styles = { getPortalledTooltipStyles ( { theme} ) } /> }
667
675
< ReactEchartsCore
668
676
ref = { ref }
0 commit comments