Skip to content

Commit

Permalink
[charts] Support RTL for y-axis (mui#13614)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored and thomasmoon committed Sep 6, 2024
1 parent bf1782d commit 438b284
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/x-charts/src/ChartsYAxis/ChartsYAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
} = defaultizedProps;

const theme = useTheme();
const isRTL = theme.direction === 'rtl';

const classes = useUtilityClasses({ ...defaultizedProps, theme });

const { left, top, width, height } = useDrawingArea();
Expand Down Expand Up @@ -101,13 +103,14 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
const TickLabel = slots?.axisTickLabel ?? ChartsText;
const Label = slots?.axisLabel ?? ChartsText;

const revertAnchor = (!isRTL && position === 'right') || (isRTL && position !== 'right');
const axisTickLabelProps = useSlotProps({
elementType: TickLabel,
externalSlotProps: slotProps?.axisTickLabel,
additionalProps: {
style: {
fontSize: tickFontSize,
textAnchor: position === 'right' ? 'start' : 'end',
textAnchor: revertAnchor ? 'start' : 'end',
dominantBaseline: 'central',
...tickLabelStyle,
},
Expand Down

0 comments on commit 438b284

Please sign in to comment.