Skip to content

RichTextToolbarButton adding dashicons makes them squashed to text #29376

@dingo-d

Description

@dingo-d

Description

When creating a custom formatting button for the RichText component using RichTextToolbarButton, if you specify the icon as the name of the dashicons icon

	return <RichTextToolbarButton
		icon='editor-indent'
		title={ __('Toggle indent') }
		onClick={() => setAttributes({[`${componentName}IsIndented`]: !isIndented})}
		isActive={ isIndented }
	/>

you get this

Screenshot 2021-02-26 at 13 59 28

However, if you use svg - and not just copy pasted one, that won't work, you need to recreate the svg using primitives

	import { SVG, Path, Rect, G } from '@wordpress/primitives';

	const indent = (
		<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
			<Rect x="0" fill="none" width="20" height="20"/>
			<G>
				<Path d="M3 5V3h9v2H3zm10-1V3h4v1h-4zm0 3h2V5l4 3.5-4 3.5v-2h-2V7zM3 8V6h9v2H3zm2 3V9h7v2H5zm-2 3v-2h9v2H3zm10 0v-1h4v1h-4zm-4 3v-2h3v2H9z"/>
			</G>
		</SVG>
	);

	return <RichTextToolbarButton
		icon={indent}
		title={ __('Toggle indent') }
		onClick={() => setAttributes({[`${componentName}IsIndented`]: !isIndented})}
		isActive={ isIndented }
	/>

It looks ok because the SVG element will be rendered instead of dashicons which is just added as a pseudo-element and has no styling for it.

Screenshot 2021-02-26 at 14 02 35

SVG elements have

.components-button.has-icon.has-text svg {
    margin-right: 8px;
}

whereas dashicons icons have

.components-button.has-icon .dashicon {
    display: inline-block;
    flex: 0 0 auto;
}

Notice the missing margin on the right.

Step-by-step reproduction instructions

Expected behaviour

Stylings should be the same

Actual behaviour

Stylings are not the same, and I need to copy and paste, then transform the SVG to 'primitives' in order to be rendered properly.

WordPress information

  • WordPress version: 5.6.2
  • Gutenberg version: Core
  • Are all plugins except Gutenberg deactivated? No, but it's a core bug, not a plugin bug.
  • Are you using a default theme (e.g. Twenty Twenty-One)? No, and it shouldn't matter, this is a part of core GB functionality

Device information

  • Device: Desktop
  • Operating system: MacOs Big Sur 11.2.1
  • Browser: Chrome Version 88.0.4324.192 (Official Build) (x86_64)

Metadata

Metadata

Assignees

Labels

[Feature] Rich TextRelated to the Rich Text component that allows developers to render a contenteditable[Package] Rich text/packages/rich-text[Status] In ProgressTracking issues with work in progress

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions