Skip to content

Changing a RichText value automatically focus the RichText #17505

@jorgefilipecosta

Description

@jorgefilipecosta

Describe the bug
Currently, if we change a RichText value the RichText gets focused and becomes the active element event if another element was focused and rich text value is changed using a programmatic interface e.g: wp.data.dispatch( 'core/block-editor' ).updateBlockAttributes( block.clientId, { content: '1<strong>234</strong>56789' } );.

Previously the popover was closed when a click outside them happened; now they are closed when the focus is outside them. This change makes the rich text automatically gaining focus problem worse. For example, if we have popover with a SelectControl that allows switching the content of a paragraph between some predefined values when the select is used, the popover closes.

Another side effect is that on PR #16014 that adds custom color as a format, each time we try to use the color picker the popover closes, because when we use the color picker there is a change in the format leaving to a change to the content of paragraph and making the focus go outside the popover.
I guess we should address this issue before WordPress 5.3 because this problem may affect third-party plugins that add color options or even other option in a popover.

I guess we may also have a11y related problems with moving the focus.

To reproduce
Steps to reproduce the behavior:

  • Insert paragraph block:
const block = wp.blocks.createBlock( 'core/paragraph', { content: '123456789' } );
wp.data.dispatch( 'core/block-editor' ).insertBlock( block );
  • Put the cursor inside the paragraph e.g. in the middle of the paragraph.
    Focus some element on the page (and verify it gets focused):
document.querySelector( 'button.editor-block-navigation' ).focus();
console.log( document.activeElement );
  • Programatically change the paragraph content and verify the paragraph becomes the active element:
	wp.data.dispatch( 'core/block-editor' ).updateBlockAttributes( block.clientId, { content: '1<strong>234</strong>56789' } );
	console.log( document.activeElement );

Sep-20-2019 18-50-38

cc: @ellatrix

Metadata

Metadata

Assignees

Labels

Backwards CompatibilityIssues or PRs that impact backwards compatability[Feature] Rich TextRelated to the Rich Text component that allows developers to render a contenteditable[Package] A11y/packages/a11y[Package] Rich text/packages/rich-text[Priority] HighUsed to indicate top priority items that need quick attention[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions