Skip to content

Commit 6074165

Browse files
committedAug 17, 2021
feat(stream): add aria attributes to the root SVG container
1 parent c94f5e2 commit 6074165

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
 

‎packages/stream/src/Stream.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ const InnerStream = <RawDatum extends StreamDatum>({
6262
enableStackTooltip = svgDefaultProps.enableStackTooltip,
6363

6464
legends = svgDefaultProps.legends,
65+
6566
role,
67+
ariaLabel,
68+
ariaLabelledBy,
69+
ariaDescribedBy,
6670
}: InnerStreamProps<RawDatum>) => {
6771
const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions(
6872
width,
@@ -209,6 +213,9 @@ const InnerStream = <RawDatum extends StreamDatum>({
209213
margin={margin}
210214
defs={boundDefs}
211215
role={role}
216+
ariaLabel={ariaLabel}
217+
ariaLabelledBy={ariaLabelledBy}
218+
ariaDescribedBy={ariaDescribedBy}
212219
>
213220
{chartLayers.map((layer, i) => {
214221
if (typeof layer === 'function') {

‎packages/stream/src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AriaAttributes } from 'react'
12
import {
23
Box,
34
Dimensions,
@@ -120,6 +121,9 @@ export type StreamCommonProps<RawDatum extends StreamDatum> = {
120121
renderWrapper: boolean
121122

122123
role: string
124+
ariaLabel: AriaAttributes['aria-label']
125+
ariaLabelledBy: AriaAttributes['aria-labelledby']
126+
ariaDescribedBy: AriaAttributes['aria-describedby']
123127
}
124128

125129
export type StreamSvgProps<RawDatum extends StreamDatum> = Partial<StreamCommonProps<RawDatum>> &

‎packages/stream/tests/Stream.test.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from 'enzyme'
22
import { Stream } from '../src'
3+
import { Bar } from '@nivo/bar'
34

45
type TestDatum = {
56
A: number
@@ -25,3 +26,30 @@ it('should render a basic stream chart', () => {
2526

2627
expect(wrapper.find('StreamLayer')).toHaveLength(3)
2728
})
29+
30+
describe('accessibility', () => {
31+
it('should forward root aria properties to the SVG element', () => {
32+
const wrapper = mount(
33+
<Stream<TestDatum>
34+
width={500}
35+
height={300}
36+
data={[
37+
{ A: 10, B: 20, C: 30 },
38+
{ A: 20, B: 10, C: 30 },
39+
{ A: 30, B: 10, C: 20 },
40+
]}
41+
keys={['A', 'B', 'C']}
42+
animate={false}
43+
ariaLabel="AriaLabel"
44+
ariaLabelledBy="AriaLabelledBy"
45+
ariaDescribedBy="AriaDescribedBy"
46+
/>
47+
)
48+
49+
const svg = wrapper.find('svg')
50+
51+
expect(svg.prop('aria-label')).toBe('AriaLabel')
52+
expect(svg.prop('aria-labelledby')).toBe('AriaLabelledBy')
53+
expect(svg.prop('aria-describedby')).toBe('AriaDescribedBy')
54+
})
55+
})

0 commit comments

Comments
 (0)
Please sign in to comment.