Skip to content

Commit

Permalink
[A11y] add aria-hidden attributes to XYPlot (#273)
Browse files Browse the repository at this point in the history
* add aria-hidden attributes to XYPlot elements

* more granual application of aria-hidden
  • Loading branch information
ekh64 authored Dec 10, 2020
1 parent d1d919d commit dd1c004
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/AreaChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default class AreaChart extends React.Component {
}

return (
<g className="rct-area-chart">
<g className="rct-area-chart" aria-hidden="true">
<path
className={`rct-area-chart-path ${pathClassName}`}
d={areaPathStr}
Expand Down
2 changes: 1 addition & 1 deletion src/AreaHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class AreaHeatmap extends React.Component {
};

return (
<g className="rct-area-heatmap-chart" {...handlers}>
<g className="rct-area-heatmap-chart" aria-hidden="true" {...handlers}>
<rect
x="0"
y="0"
Expand Down
3 changes: 2 additions & 1 deletion src/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default class Bar extends React.Component {

const rect = (
<rect
aria-hidden="true"
{...{
x: rectX,
y: rectY,
Expand Down Expand Up @@ -216,7 +217,7 @@ export default class Bar extends React.Component {

if (showLabel) {
return (
<g>
<g aria-hidden="true">
{rect}
{text}
</g>
Expand Down
2 changes: 1 addition & 1 deletion src/ColorHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default class ColorHeatmap extends React.Component {
}

return (
<g className="rct-color-heatmap-chart">
<g className="rct-color-heatmap-chart" aria-hidden="true">
{data.map((d, i) => {
const color = colorScale(valueAccessor(d));
const style = { ...getValue(rectStyle, d, i), fill: color };
Expand Down
2 changes: 1 addition & 1 deletion src/FunnelChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class FunnelChart extends React.Component {
const colors = scaleOrdinal(schemeCategory10).domain(range(10));

return (
<g className="rct-funnel-chart">
<g className="rct-funnel-chart" aria-hidden="true">
{data.map((d, i) => {
if (i === 0) return null;
const pathStr = funnelArea([data[i - 1], d]);
Expand Down
2 changes: 1 addition & 1 deletion src/LineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class LineChart extends React.Component {
.y((d, i) => yScale(getValue(y, d, i)))(data);

return (
<g className={`rct-line-chart ${lineClassName}`}>
<g className={`rct-line-chart ${lineClassName}`} aria-hidden="true">
<path className="rct-line-path" d={pathStr} style={lineStyle} />
</g>
);
Expand Down
2 changes: 1 addition & 1 deletion src/MarkerLineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export default class MarkerLineChart extends React.Component {
render() {
const tickType = getTickType(this.props);
return (
<g className="rct-marker-line-chart">
<g className="rct-marker-line-chart" aria-hidden="true">
{tickType === 'RangeValue'
? this.props.data.map(this.renderRangeValueLine)
: this.props.data.map(this.renderValueValueLine)}
Expand Down
2 changes: 1 addition & 1 deletion src/RangeBarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default class RangeBarChart extends React.Component {
} = this.props;

return (
<g>
<g aria-hidden="true">
{data.map((d, i) => {
const [onMouseEnter, onMouseMove, onMouseLeave, onClick] = [
'onMouseEnterBar',
Expand Down
1 change: 1 addition & 0 deletions src/RangeRect.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default class RangeRect extends React.Component {

return (
<rect
aria-hidden="true"
{...{
x: rectX,
y: rectY,
Expand Down
2 changes: 1 addition & 1 deletion src/ScatterPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ export default class ScatterPlot extends React.Component {
};

render() {
return <g>{this.props.data.map(this.renderPoint)}</g>;
return <g aria-hidden="true">{this.props.data.map(this.renderPoint)}</g>;
}
}
1 change: 1 addition & 0 deletions src/XAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default class XAxis extends React.Component {
return (
<g
className="rct-chart-axis rct-chart-axis-x"
aria-hidden="true"
onMouseMove={this.handleOnMouseMove}
onMouseEnter={this.handleOnMouseEnter}
onMouseLeave={this.handleOnMouseLeave}
Expand Down
1 change: 1 addition & 0 deletions src/XAxisLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class XAxisLabels extends React.Component {
return (
<g
key={`x-axis-label-${i}`}
aria-hidden="true"
{...{ onMouseEnter, onMouseMove, onMouseLeave, onClick }}
>
{/* <XAxisLabelDebugRect {...{x, y, label}}/> */}
Expand Down
5 changes: 4 additions & 1 deletion src/XAxisTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export default class XAxisTitle extends React.Component {
: '-0.2em';

return (
<g transform={`translate(${translateX},${translateY})`}>
<g
transform={`translate(${translateX},${translateY})`}
aria-hidden="true"
>
<text
style={{ ...style, textAnchor }}
transform={`rotate(${rotate})`}
Expand Down
2 changes: 1 addition & 1 deletion src/XGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class XGrid extends React.Component {
const className = `rct-chart-grid-line ${lineClassName || ''}`;

return (
<g className="rct-chart-grid-x">
<g className="rct-chart-grid-x" aria-hidden="true">
{ticks.map((tick, i) => {
return (
<XLine
Expand Down
1 change: 1 addition & 0 deletions src/XLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class XLine extends React.Component {

return (
<line
aria-hidden="true"
{...{
x1: lineX,
x2: lineX,
Expand Down
2 changes: 1 addition & 1 deletion src/XTicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class XTicks extends React.Component {
: `translate(0, ${-spacingTop || 0})`;

return (
<g className="rct-chart-ticks-x" transform={transform}>
<g className="rct-chart-ticks-x" transform={transform} aria-hidden="true">
{ticks.map((tick, i) => {
const x1 = xScale(tick);
const y2 = placement === 'above' ? -tickLength : tickLength;
Expand Down
17 changes: 11 additions & 6 deletions src/XYPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ function getMouseOptions(
const xValue = !inRange(innerX, 0, chartSize.width)
? null
: xScaleType === 'ordinal'
? invertPointScale(xScale, innerX)
: xScale.invert(innerX);
? invertPointScale(xScale, innerX)
: xScale.invert(innerX);

const yValue = !inRange(innerY, 0, chartSize.height)
? null
: yScaleType === 'ordinal'
? invertPointScale(yScale, innerY)
: yScale.invert(innerY);
? invertPointScale(yScale, innerY)
: yScale.invert(innerY);

return {
event,
Expand Down Expand Up @@ -212,7 +212,7 @@ class XYPlot extends React.Component {
onMouseUp = this.onXYMouseEvent.bind(this, 'onMouseUp');
onClick = this.onXYMouseEvent.bind(this, 'onClick');
onMouseEnter = this.onXYMouseEvent.bind(this, 'onMouseEnter');
onMouseLeave = this.onXYMouseEvent.bind(this, 'onMouseLeave')
onMouseLeave = this.onXYMouseEvent.bind(this, 'onMouseLeave');

render() {
const {
Expand Down Expand Up @@ -295,7 +295,11 @@ class XYPlot extends React.Component {
{...{ width, height, className, style: xyPlotContainerStyle }}
{...handlers}
>
<rect className="rct-chart-background" {...{ width, height }} />
<rect
className="rct-chart-background"
{...{ width, height }}
aria-hidden="true"
/>
<g
transform={`translate(${marginLeft + spacingLeft}, ${marginTop +
spacingTop})`}
Expand All @@ -305,6 +309,7 @@ class XYPlot extends React.Component {
transform={`translate(${-spacingLeft}, ${-spacingTop})`}
className="rct-plot-background"
style={xyPlotStyle}
aria-hidden="true"
{...panelSize}
/>
{React.Children.map(this.props.children, child => {
Expand Down
1 change: 1 addition & 0 deletions src/YAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export default class YAxis extends React.Component {
onMouseEnter={this.handleOnMouseEnter}
onMouseLeave={this.handleOnMouseLeave}
onClick={this.handleOnClick}
aria-hidden="true"
>
{showGrid ? <YGrid {...gridProps} /> : null}

Expand Down
6 changes: 5 additions & 1 deletion src/YAxisLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ class YAxisLabels extends React.Component {
: `translate(${width + spacingRight}, 0)`;

return (
<g className="rct-chart-value-labels-y" transform={transform}>
<g
className="rct-chart-value-labels-y"
transform={transform}
aria-hidden="true"
>
{labels.map((label, i) => {
const y = yScale(label.value) + offset;
const x = placement === 'before' ? -distance : distance;
Expand Down
5 changes: 4 additions & 1 deletion src/YAxisTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ export default class YAxisTitle extends React.Component {
: null;

return (
<g transform={`translate(${translateX},${translateY})`}>
<g
transform={`translate(${translateX},${translateY})`}
aria-hidden="true"
>
<text
style={{ ...style, textAnchor }}
transform={`rotate(${rotate})`}
Expand Down
2 changes: 1 addition & 1 deletion src/YGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class YGrid extends React.Component {
const className = `rct-chart-grid-line ${lineClassName || ''}`;

return (
<g className="rct-chart-grid-y">
<g className="rct-chart-grid-y" aria-hidden="true">
{ticks.map((tick, i) => {
return (
<YLine
Expand Down
1 change: 1 addition & 0 deletions src/YLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class YLine extends React.Component {

return (
<line
aria-hidden="true"
{...{
x1: -spacingLeft,
x2: lineX,
Expand Down
2 changes: 1 addition & 1 deletion src/YTicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class YTicks extends React.Component {
: `translate(${-spacingLeft || 0}, 0)`;

return (
<g className="rct-chart-ticks-y" transform={transform}>
<g className="rct-chart-ticks-y" transform={transform} aria-hidden="true">
{ticks.map((tick, i) => {
const y1 = yScale(tick);
const x2 = placement === 'before' ? -tickLength : tickLength;
Expand Down

0 comments on commit dd1c004

Please sign in to comment.