diff --git a/src/chart.tsx b/src/chart.tsx index 55a6c52..ca5ce47 100644 --- a/src/chart.tsx +++ b/src/chart.tsx @@ -112,7 +112,8 @@ export default function DefaultChart(props: ChartProps) { setCanvasRef(el))} height={merged.height} - width={merged.width}> + width={merged.width} + {...merged.extraCanvasAttributes}> {merged.fallback} ) diff --git a/src/types.ts b/src/types.ts index b69cc12..1505a60 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type { Ref } from '@solid-primitives/refs' import type { ChartData, ChartOptions, Plugin, ChartTypeRegistry } from 'chart.js' -import type { JSXElement } from 'solid-js' +import type { JSXElement, JSX } from 'solid-js' /** * Chart props @@ -52,4 +52,14 @@ export interface ChartProps { * @default null */ ref?: Ref + /** + * Extra attributes to be forwarded directly to the canvas + * + * For example for setting the `id`, `role`, or `aria-label`. + * + * This can be used for any attribute except `width` and `height`, + * which can be set directly. + * @default {} + */ + extraCanvasAttributes?: Omit, 'width' | 'height'> }