gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

RichText Editor core/underline missing

Open aceArt-GmbH opened this issue 2 years ago • 3 comments

Description

<RichText /> should allow underlining text. There is code for it in this repo https://github.com/WordPress/gutenberg/tree/trunk/packages/format-library/src/underline. But it does not show up as option

Step-by-step reproduction instructions

  1. npx @wordpress/create-block starter-block
  2. cd starter-block
  3. wp-env start
  4. npm start
  5. Add the RichText editor to the edit.js
import { RichText } from "@wordpress/block-editor";
<RichText
	tagName="div"
	value={attributes.test}
	onChange={(test) => setAttributes({ test })}
/>
  1. see no underline

Screenshots, screen recording, code snippet

image

Workaround:

/*
	Register underline button to rich text editor
	https://developer.wordpress.org/block-editor/how-to-guides/format-api/
*/
const UnderlineButton = ({ isActive, onChange, value }) => {
	return (
		<RichTextToolbarButton
			icon="editor-underline"
			title="Unterstrichen"
			onClick={() => {
				onChange(
					toggleFormat(value, {
						type: "my-project/underline",
					})
				);
			}}
			isActive={isActive}
		/>
	);
};

registerFormatType("my-project/underline", {
	title: "Unterstrichen",
	tagName: "u",
	className: null,
	edit: UnderlineButton,
});

Environment info

  • Wordpress 6.1.1
  • "@wordpress/scripts": "^25.2.0"
  • Chromium and Firefox on Linux

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

aceArt-GmbH avatar Jan 27 '23 09:01 aceArt-GmbH

Hi @aceArt-GmbH, The underline can be run from the shortcut, but as far as I know, it is intentional that it is not shown in the dropdown. The following topics will give you some background information.

  • #43616
  • #7162
  • #13117

t-hamano avatar Jan 27 '23 12:01 t-hamano

okay, if this is intentional it should at least be documented somewhere in the RichText documentation with a way to re-enable it if someone wants it. Or if you can not re-enable it, feel free to include my workaround

aceArt-GmbH avatar Jan 30 '23 07:01 aceArt-GmbH

The first underline button was removed in WordPress 4.7, before Gutenberg was introduced.

This article states that it was removed due to accessibility issues. I think it would be inappropriate to dare to document how to enable this. If there are developers who want to enable this, I think they can implement it with reference to Formatting Toolbar API.

@ellatrix I would love to hear any feedback on documenting how to re-enable the underline button.

t-hamano avatar Jan 30 '23 12:01 t-hamano

Just checking in on this issue - to see if there's anything we need to discuss/decide and action - or if it can be closed?

jordesign avatar Jul 28 '23 00:07 jordesign

@jordesign Thanks for digging up this issue.

As I have commented several times on this issue, I believe the removal of the core/underline shortcut button was not appropriate from an accessibility standpoint and was removed after discussion and consensus.

Developers who really want to add that button could look at the Formatting Toolbar API documentation and implement it, and I don't think we should put a deprecated method on the site.

@aceArt-GmbH

I would like to close this issue, but if you have any suggestions feel free to comment.

t-hamano avatar Jul 28 '23 12:07 t-hamano