Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/marimekko/src/Marimekko.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const InnerMarimekko = <Datum,>({
onMouseLeave,
legends = svgDefaultProps.legends,
role,
ariaLabel,
ariaLabelledBy,
ariaDescribedBy,
forwardedRef,
}: MarimekkoSvgProps<Datum> & {
forwardedRef: Ref<SVGSVGElement>
Expand Down Expand Up @@ -169,6 +172,9 @@ const InnerMarimekko = <Datum,>({
margin={margin}
defs={boundDefs}
role={role}
ariaLabel={ariaLabel}
ariaLabelledBy={ariaLabelledBy}
ariaDescribedBy={ariaDescribedBy}
ref={forwardedRef}
>
{layers.map((layer, i) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/marimekko/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AriaAttributes } from 'react'
import * as React from 'react'
import {
stackOffsetDiverging,
Expand Down Expand Up @@ -131,6 +132,9 @@ export interface MarimekkoCommonProps<Datum> {
tooltip: BarTooltipType<Datum>
legends: readonly LegendProps[]
role?: string
ariaLabel?: AriaAttributes['aria-label']
ariaLabelledBy?: AriaAttributes['aria-labelledby']
ariaDescribedBy?: AriaAttributes['aria-describedby']
}

export type MouseEventHandler<Datum, ElementType> = (
Expand Down
19 changes: 19 additions & 0 deletions packages/marimekko/tests/Marimekko.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,22 @@ describe('layout', () => {
expect(sizes[2].height).toBeGreaterThan(sizes[0].height)
})
})

describe('accessibility', () => {
it('should forward root aria properties to the SVG element', () => {
const wrapper = mount(
<Marimekko
{...commonProps}
ariaLabel="AriaLabel"
ariaLabelledBy="AriaLabelledBy"
ariaDescribedBy="AriaDescribedBy"
/>
)

const svg = wrapper.find('svg')

expect(svg.prop('aria-label')).toBe('AriaLabel')
expect(svg.prop('aria-labelledby')).toBe('AriaLabelledBy')
expect(svg.prop('aria-describedby')).toBe('AriaDescribedBy')
})
})