Canvas

A freehand drawing surface with pen and eraser tools, color palette, variable stroke widths, undo/redo, and PNG download.

Installation

npx dafink-ui add canvas

Demo

Props

NameTypeDefaultDescription
widthnumbercontainer widthCanvas width in px. Defaults to responsive container width.
heightnumber400Canvas height in px.
defaultColorstring'#18181b'Initial stroke color.
defaultStrokeWidthnumber4Initial stroke width in px.
showToolbarbooleantrueWhether to render the built-in toolbar.
classNamestring""Extra classes on the wrapper div.

Accessibility

Canvas has no custom focus management: every toolbar control (tool selector, color swatches, stroke width, undo/redo, clear, download) is a native button reachable with Tab and activated with Enter/Space, in plain document order. The color swatches expose role="radio" inside a role="radiogroup", but there is no roving-tabindex or arrow-key handling wired up for that group, so in practice each swatch is its own ordinary tab stop rather than following the full ARIA radiogroup keyboard pattern. The drawing surface itself is pointer-only: it's exposed to assistive tech as a static role="img" with aria-label="Drawing canvas", since there is no keyboard equivalent for freehand drawing.