Skip to content

fix(svg): emit custom HTML attributes on the svg root - #836

Open
orshih6 wants to merge 1 commit into
CoreBunch:mainfrom
orshih6:contribot/issue-834
Open

orshih6 wants to merge 1 commit into
CoreBunch:mainfrom
orshih6:contribot/issue-834

Conversation

@orshih6

@orshih6 orshih6 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The Attributes tab is offered for every node, but base.svg never declared an htmlAttributes prop. Its render() and canvas editor ignored the bag, so an aria-label or data-* added to an SVG was saved but never reached the page.

Changes:

  • base.svg now declares htmlAttributes in its TypeBox props schema and property schema, like the other base modules.
  • render() adds the attributes to the opening <svg> tag using the shared htmlAttributesAttr. It goes through the same normalizeHtmlAttributes sanitisation gate, so event handlers, class/style, reserved runtime names and dangerous URL schemes are still dropped. The title-derived role/aria-label comes first, then the authored attributes, then the markup's own root attributes. Earlier attributes win in HTML, so the accessible-label setting overrides a custom aria-label, and custom attributes override same-named attributes already in the pasted markup.
  • SvgEditor spreads the same normalised attributes onto the canvas root, in the same precedence, so the editor matches the published output. An authored hidden goes through the existing useCanvasHiddenAttribute path.

Inputs and checkboxes already publish htmlAttributes on the current main branch, so they need no change here. The new integration tests cover them anyway, so a regression would show up.

Testing:

  • New publisher integration tests render base.button, base.input, base.checkbox and base.svg through renderNode with the real registry. They assert that aria-label and a data-* attribute appear on the element's own tag. A separate SVG case checks sanitisation, escaping and ordering next to the title label.
  • A new canvas test checks that the SVG editor root gets the authored attributes and drops onclick.
  • Without the module change, the SVG tests fail. The button, input and checkbox cases pass either way.
  • bun test on the touched test files and the SVG import tests, eslint on the changed files and tsc --noEmit -p tsconfig.app.json all pass.

🤖 Generated with Claude Code

Fixes #834


This change was prepared with an AI coding agent (Claude) and opened automatically after an automated review, so no person has read it yet. I'm happy to make any changes you'd like.

Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Additional attributes only display on published page for a button

1 participant