Custom mark toolbar buttons shrink on hover, and SVG icons only render a single <path>

What is the URL?

Relevant URL: not project-specific. It happens on any Structured Text field where a plugin adds custom marks. Happy to share a private link by email if you need to see our project.

What is the issue?

I need help with: custom mark buttons in the Structured Text toolbar, which shrink on hover, and their SVG icons, which only render a single <path>.

We have a private plugin (datocms-plugin-sdk 2.5.0) that adds two text color marks to Structured Text fields through customMarksForStructuredTextField.

1. Custom mark buttons shrink on hover

Our custom mark buttons shrink when hovered. The native buttons (bold, italic, highlight
) don’t. The plugin ships no CSS: it only returns { id, label, icon, appliedStyle }. It happens with a Font Awesome icon name ('palette', 'circle') and with a custom SVG icon alike.

Steps to reproduce:

  1. Install a plugin that returns custom marks from customMarksForStructuredTextField
  2. Open a record with a Structured Text field where those marks are enabled
  3. Hover the custom mark buttons in the toolbar: they shrink, the native ones don’t

2. SVG icons: only one <path> is rendered, colors are dropped

We tried a “text color” icon: a letter path plus a colored bar under it. Only the letter showed up. The <rect> and its fill color were dropped:

{
  id: 'red',
  label: 'Rouge',
  icon: {
    type: 'svg',
    viewBox: '0 0 24 24',
    content: '<path fill="currentColor" d="..."/><rect x="4" y="18.5" width="16" height="3.5" rx="1" fill="#e80000"/>',
  },
  appliedStyle: { color: '#e80000' },
}

We worked around it with single-path, single-color icons (one letter per mark). Could you confirm which SVG elements and attributes are supported in toolbar icons?

Browser: Chrome 158.0.8127.88 (x86_64)

Thanks!

Hello @annabelle.cuda,

Thank for you the report, and sorry about this!

  1. Shrinking on hover: Reported and PRed.
  2. SVG allow list: For now only <path> is allowed, with the d and fill attributes. You can combine multiple paths and/or colors this way. But this seems like overly strict sanitization to me; I’ll mention it to the devs too and see if we can safely expand the allowlist (and update docs accordingly) to allow geometric primitives, gradients, etc.

I’ll let you know once these are fixed.

Thanks a lot for the quick answer and for the PR!

Good to know that several elements with their own fill are allowed: we’ll draw the colored bar as a second path, which solves our case for now. A wider allowlist would still be welcome, and an update of the SVG icon docs listing what’s supported would have saved us a few tries.

Looking forward to the hover fix. Thanks again!

Both bugs should be fixed now, @annabelle.cuda!

We took a different approach to the <rect> issue and now all normal SVG elements should work as long as they don’t call external url()s or run scripts. Please try it when you get a chance and let me know if anything still looks wrong.

The fix was on the DatoCMS app side; you don’t need to upgrade your plugins-sdk or change any plugin code. The old, original SVG should just work now, hopefully.