-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
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 );
cc: @ellatrix