Skip to content

Commit

Permalink
feat(a11y): add changes to allow for improved accessibility on charts (
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-1234 committed Sep 12, 2020
1 parent ce9a172 commit 464185c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/axes/index.d.ts
Expand Up @@ -37,6 +37,7 @@ declare module '@nivo/axes' {
legend?: React.ReactNode
legendPosition?: 'start' | 'middle' | 'end'
legendOffset?: number
ariaHidden?: boolean
}

export interface GridProps extends Dimensions, Scales {
Expand Down
4 changes: 3 additions & 1 deletion packages/axes/src/components/Axis.js
Expand Up @@ -33,6 +33,7 @@ const Axis = ({
legendPosition,
legendOffset,
onClick,
ariaHidden,
}) => {
const theme = useTheme()

Expand Down Expand Up @@ -133,7 +134,7 @@ const Axis = ({
})

return (
<animated.g transform={animatedProps.transform}>
<animated.g transform={animatedProps.transform} aria-hidden={ariaHidden}>
{transitions.map(({ item: tick, props: transitionProps, key }, tickIndex) => {
return React.createElement(renderTick, {
tickIndex,
Expand Down Expand Up @@ -176,6 +177,7 @@ Axis.propTypes = {
legendPosition: PropTypes.oneOf(['start', 'middle', 'end']).isRequired,
legendOffset: PropTypes.number.isRequired,
onClick: PropTypes.func,
ariaHidden: PropTypes.bool,
}
Axis.defaultProps = {
x: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/axes/src/props.js
Expand Up @@ -25,6 +25,7 @@ export const axisPropTypes = {
legend: PropTypes.node,
legendPosition: PropTypes.oneOf(['start', 'middle', 'end']),
legendOffset: PropTypes.number,
ariaHidden: PropTypes.bool,
}

export const axisPropType = PropTypes.shape(axisPropTypes)
2 changes: 2 additions & 0 deletions packages/bar/index.d.ts
Expand Up @@ -132,6 +132,8 @@ declare module '@nivo/bar' {
legends: ({ dataFrom: 'indexes' | 'keys' } & LegendProps)[]

markers: CartesianMarkerProps[]

role: string
}>

export enum BarLayerType {
Expand Down
3 changes: 3 additions & 0 deletions packages/bar/src/Bar.js
Expand Up @@ -108,6 +108,8 @@ const Bar = props => {
animate,
motionStiffness,
motionDamping,

role,
} = props
const options = {
layout,
Expand Down Expand Up @@ -315,6 +317,7 @@ const Bar = props => {
margin={margin}
defs={boundDefs}
theme={theme}
role={role}
>
{layers.map((layer, i) => {
if (typeof layer === 'function') {
Expand Down
4 changes: 4 additions & 0 deletions packages/bar/src/props.js
Expand Up @@ -92,6 +92,8 @@ export const BarPropTypes = {
).isRequired,

pixelRatio: PropTypes.number.isRequired,

role: PropTypes.string,
}

export const BarDefaultProps = {
Expand Down Expand Up @@ -141,4 +143,6 @@ export const BarDefaultProps = {

pixelRatio:
global.window && global.window.devicePixelRatio ? global.window.devicePixelRatio : 1,

role: 'img',
}
5 changes: 3 additions & 2 deletions packages/core/src/components/SvgWrapper.js
Expand Up @@ -11,11 +11,11 @@ import PropTypes from 'prop-types'
import { Defs } from './defs'
import { useTheme } from '../theming'

const SvgWrapper = ({ width, height, margin, defs, children }) => {
const SvgWrapper = ({ width, height, margin, defs, children, role }) => {
const theme = useTheme()

return (
<svg xmlns="http://www.w3.org/2000/svg" role="img" width={width} height={height}>
<svg xmlns="http://www.w3.org/2000/svg" role={role} width={width} height={height}>
<Defs defs={defs} />
<rect width={width} height={height} fill={theme.background} />
<g transform={`translate(${margin.left},${margin.top})`}>{children}</g>
Expand All @@ -32,6 +32,7 @@ SvgWrapper.propTypes = {
}).isRequired,
defs: PropTypes.array,
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
role: PropTypes.string,
}

export default SvgWrapper

0 comments on commit 464185c

Please sign in to comment.