Skip to content

Commit 711fcf8

Browse files
Anush2303Anush
andauthored
fix(react-charts): fix accessibility bugs (#34609)
Co-authored-by: Anush <anushgupta@microsoft.com>
1 parent da0eefb commit 711fcf8

File tree

7 files changed

+18
-23
lines changed

7 files changed

+18
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix accessibility bugs",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "anushgupta@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charts/library/src/components/CommonComponents/CartesianChart.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,7 @@ export const CartesianChart: React.FunctionComponent<ModifiedCartesianChartProps
630630
content={props.yAxisTitle}
631631
textProps={{
632632
x: (yAxisTitleMaximumAllowedHeight - margins.bottom!) / 2 + removalValueForTextTuncate!,
633-
y: _useRtl
634-
? svgDimensions.width - margins.right! / 2 + titleMargin
635-
: margins.left! / 2 + startFromX - titleMargin,
633+
y: _useRtl ? svgDimensions.width - margins.right! / 2 + titleMargin : margins.left! / 2 - titleMargin,
636634
textAnchor: 'middle',
637635
transform: `translate(0,
638636
${svgDimensions.height - margins.bottom! - margins.top! - titleMargin})rotate(-90)`,

packages/charts/react-charts/library/src/components/GroupedVerticalBarChart/GroupedVerticalBarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export const GroupedVerticalBarChart: React.FC<GroupedVerticalBarChartProps> = R
419419
onBlur={_onBarLeave}
420420
onClick={pointData.onClick}
421421
aria-label={getAriaLabel(pointData, singleSet.xAxisPoint)}
422-
tabIndex={pointData.legend !== '' ? 0 : undefined}
422+
tabIndex={_legendHighlighted(pointData.legend) || _noLegendHighlighted() ? 0 : undefined}
423423
role="img"
424424
/>
425425
</React.Fragment>,

packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
456456
cy={_yAxisScale(y1)}
457457
fill={activePoint === circleId ? tokens.colorNeutralBackground1 : lineColor}
458458
opacity={isLegendSelected ? 1 : 0.1}
459-
tabIndex={_points[i].legend !== '' ? 0 : undefined}
459+
tabIndex={isLegendSelected ? 0 : undefined}
460460
onMouseOver={(event: React.MouseEvent<SVGElement>) =>
461461
_handleHover(
462462
x1,
@@ -558,7 +558,7 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
558558
onMouseOut={_handleMouseOut}
559559
{..._getClickHandler(_points[i].onLineClick)}
560560
opacity={1}
561-
tabIndex={_points[i].legend !== '' ? 0 : undefined}
561+
tabIndex={isLegendSelected ? 0 : undefined}
562562
/>,
563563
);
564564
} else {
@@ -654,7 +654,7 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
654654
strokeWidth={strokeWidth}
655655
role="img"
656656
aria-label={_getAriaLabel(i, j - 1)}
657-
tabIndex={_points[i].legend !== '' ? 0 : undefined}
657+
tabIndex={isLegendSelected ? 0 : undefined}
658658
/>,
659659
);
660660
if (j + 1 === _points[i].data.length) {
@@ -708,7 +708,7 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
708708
strokeWidth={strokeWidth}
709709
role="img"
710710
aria-label={_getAriaLabel(i, j)}
711-
tabIndex={_points[i].legend !== '' ? 0 : undefined}
711+
tabIndex={isLegendSelected ? 0 : undefined}
712712
/>
713713
{/* Dummy circle acting as magnetic latch for last callout point */}
714714
<circle

packages/charts/react-charts/library/src/components/ScatterChart/ScatterChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export const ScatterChart: React.FunctionComponent<ScatterChartProps> = React.fo
331331
stroke={seriesColor}
332332
role="img"
333333
aria-label={_getAriaLabel(i, j)}
334-
tabIndex={_points[i].legend !== '' ? 0 : undefined}
334+
tabIndex={isLegendSelected ? 0 : undefined}
335335
/>,
336336
);
337337
}

packages/charts/react-charts/library/src/components/Sparkline/useSparklineStyles.styles.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { makeStyles, mergeClasses } from '@griffel/react';
22
import { SparklineProps, SparklineStyles } from './Sparkline.types';
33
import type { SlotClassNames } from '@fluentui/react-utilities';
44
import { tokens, typographyStyles } from '@fluentui/react-theme';
5-
import { HighContrastSelector } from '../../utilities/index';
65

76
/**
87
* @internal
@@ -22,11 +21,7 @@ const useStyles = makeStyles({
2221
valueText: {
2322
...typographyStyles.caption1,
2423
fill: tokens.colorNeutralForeground1,
25-
[HighContrastSelector]: {
26-
opacity: 0.1,
27-
stroke: 'rgb(179, 179, 179)',
28-
forcedColorAdjust: 'none',
29-
},
24+
forcedColorAdjust: 'auto',
3025
},
3126
});
3227

packages/charts/react-charts/library/src/utilities/SVGTooltipText.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Async } from './async-utils';
66
import { KeyCodes } from './KeyCodes';
77
import { useId } from '@fluentui/react-utilities';
88
import { tokens } from '@fluentui/react-theme';
9-
import { useRtl } from './utilities';
109

1110
interface SVGTooltipTextProps {
1211
closeDelay?: number;
@@ -28,8 +27,6 @@ export const SVGTooltipText: React.FunctionComponent<SVGTooltipTextProps> = Reac
2827
>((props, forwardedRef) => {
2928
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
3029
const [isOverflowing, setIsOverflowing] = useState(false);
31-
const [textX, setTextX] = useState(0);
32-
const [textY, setTextY] = useState(0);
3330
const [textWidth, setTextWidth] = useState(0);
3431
const [textHeight, setTextHeight] = useState(0);
3532

@@ -58,8 +55,6 @@ export const SVGTooltipText: React.FunctionComponent<SVGTooltipTextProps> = Reac
5855
const measureText = useCallback((): void => {
5956
if (tooltipHostRef.current && typeof tooltipHostRef.current.getBBox === 'function') {
6057
const bbox = tooltipHostRef.current.getBBox();
61-
setTextX(bbox.x);
62-
setTextY(bbox.y);
6358
setTextWidth(bbox.width);
6459
setTextHeight(bbox.height);
6560
}
@@ -168,15 +163,15 @@ export const SVGTooltipText: React.FunctionComponent<SVGTooltipTextProps> = Reac
168163
(props.isTooltipVisibleProp && isOverflowing && !!props.content) || (isTooltipVisible && !!props.content);
169164

170165
const backgroundColor = tokens.colorNeutralBackground1;
171-
const isRTL = useRtl();
172-
const rectX = isRTL ? (textX ?? 0) + (textWidth ?? 0) - PADDING : (textX ?? 0) - PADDING;
166+
const rectX = (typeof props.textProps?.x === 'number' ? props.textProps.x : 0) - (textWidth ?? 0) / 2 - PADDING;
167+
const rectY = (typeof props.textProps?.y === 'number' ? props.textProps.y : 0) - (textHeight ?? 0) / 2 - PADDING;
173168

174169
return (
175170
<>
176171
{props.showBackground && (
177172
<rect
178173
x={rectX}
179-
y={(textY ?? 0) - PADDING}
174+
y={rectY}
180175
width={(textWidth ?? 0) + 2 * PADDING}
181176
height={(textHeight ?? 0) + 2 * PADDING}
182177
fill={backgroundColor}

0 commit comments

Comments
 (0)