Skip to content

Commit 7b47e8b

Browse files
[charts-pro] Fix zoom slider preview having an opaque background in dark mode (#20367)
1 parent 45baf17 commit 7b47e8b

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

packages/x-charts-pro/src/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const ZoomSliderActiveTrackRect = styled('rect', {
4040
props: { preview: true },
4141
style: {
4242
fill: 'transparent',
43+
// Increases the specificity to override the default fill
44+
...theme.applyStyles('dark', {
45+
fill: 'transparent',
46+
}),
4347
rx: 4,
4448
ry: 4,
4549
stroke: theme.palette.grey[500],

test/regressions/charts/ZoomSliderPreview.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { XAxis } from '@mui/x-charts/models';
33
import { BarChartPro, BarChartProProps } from '@mui/x-charts-pro/BarChartPro';
44
import { shareOfRenewables } from 'docsx/data/charts/dataset/shareOfRenewables';
55
import { countryData } from 'docsx/data/charts/dataset/countryData';
6+
import { createTheme, ThemeProvider } from '@mui/material/styles';
7+
import { Stack } from '@mui/material';
8+
9+
const darkTheme = createTheme({ palette: { mode: 'dark' } });
610

711
const percentageFormatter = new Intl.NumberFormat(undefined, {
812
style: 'percent',
@@ -31,15 +35,19 @@ const barSettings = {
3135

3236
export default function ZoomSliderPreview() {
3337
return (
34-
<BarChartPro
35-
{...barSettings}
36-
xAxis={[
37-
{
38-
...barXAxis,
39-
zoom: { filterMode: 'discard', slider: { enabled: true, preview: true } },
40-
},
41-
]}
42-
zoomData={[{ axisId: 'x', start: 10, end: 30 }]}
43-
/>
38+
<ThemeProvider theme={darkTheme}>
39+
<Stack width="100%" sx={(theme) => ({ background: theme.palette.background.default })}>
40+
<BarChartPro
41+
{...barSettings}
42+
xAxis={[
43+
{
44+
...barXAxis,
45+
zoom: { filterMode: 'discard', slider: { enabled: true, preview: true } },
46+
},
47+
]}
48+
zoomData={[{ axisId: 'x', start: 10, end: 30 }]}
49+
/>
50+
</Stack>
51+
</ThemeProvider>
4452
);
4553
}

0 commit comments

Comments
 (0)