Skip to content

Commit 1df6e9e

Browse files
[charts] Improve tooltip placement in mobile (#16553)
1 parent 2356ce0 commit 1df6e9e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import HTMLElementType from '@mui/utils/HTMLElementType';
55
import useLazyRef from '@mui/utils/useLazyRef';
66
import { styled, useThemeProps } from '@mui/material/styles';
7-
import Popper, { PopperProps } from '@mui/material/Popper';
7+
import Popper, { PopperPlacementType, PopperProps } from '@mui/material/Popper';
88
import NoSsr from '@mui/material/NoSsr';
99
import { useSvgRef } from '../hooks/useSvgRef';
1010
import { AxisDefaultized } from '../models/axis';
@@ -131,7 +131,15 @@ function ChartsTooltipContainer(inProps: ChartsTooltipContainerProps) {
131131
{
132132
name: 'offset',
133133
options: {
134-
offset: [0, pointerType?.pointerType === 'touch' ? 40 - pointerType.height : 0],
134+
offset: ({ placement }: { placement: PopperPlacementType }) => {
135+
if (pointerType?.pointerType !== 'touch') {
136+
return [0, 0];
137+
}
138+
139+
const isBottom = placement.startsWith('bottom');
140+
const placementOffset = isBottom ? 32 : 8;
141+
return [0, pointerType.height + placementOffset];
142+
},
135143
},
136144
},
137145
]}

0 commit comments

Comments
 (0)