Skip to content

Commit

Permalink
Fix primefaces#3892: Charts add accesibility to canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 25, 2023
1 parent 2e55e7b commit aae83aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions components/doc/chart/apidoc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { DevelopmentSection } from '../common/developmentsection';
import { DocSectionText } from '../common/docsectiontext';
import { DocSubSection } from '../common/docsubsection';
import { CodeHighlight } from '../common/codehighlight';

export function ApiDoc(props) {
return (
Expand Down Expand Up @@ -73,6 +71,12 @@ export function ApiDoc(props) {
<td>null</td>
<td>Style class of the element.</td>
</tr>
<tr>
<td>ariaLabel</td>
<td>string</td>
<td>options.plugins.title.text</td>
<td>ARIA label for the chart canvas. Defaults to options.plugins.title.text if available.</td>
</tr>
</tbody>
</table>
</div>
Expand Down
5 changes: 4 additions & 1 deletion components/lib/chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ const PrimeReactChart = React.memo(
const otherProps = ObjectUtils.findDiffKeys(props, PrimeReactChart.defaultProps);
const className = classNames('p-chart', props.className);
const style = Object.assign({ width: props.width, height: props.height }, props.style);
const title = props.options && props.options.plugins && props.options.plugins.title && props.options.plugins.title.text;
const ariaLabel = props.ariaLabel || title;

return (
<div id={props.id} ref={elementRef} style={style} className={className} {...otherProps}>
<canvas ref={canvasRef} width={props.width} height={props.height}></canvas>
<canvas ref={canvasRef} width={props.width} height={props.height} role="img" aria-label={ariaLabel}></canvas>
</div>
);
}),
Expand All @@ -102,6 +104,7 @@ PrimeReactChart.defaultProps = {
width: null,
height: null,
style: null,
ariaLabel: null,
className: null
};

Expand Down
5 changes: 5 additions & 0 deletions components/lib/chart/chart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export interface ChartProps {
* Style class of the element.
*/
className?: string | undefined;
/**
* ARIA label for the chart canvas. Defaults to options.plugins.title.text if available.
* @default options.plugins.title.text
*/
ariaLabel?: string | undefined;
/**
* Used to get the child elements of the component.
* @readonly
Expand Down

0 comments on commit aae83aa

Please sign in to comment.